Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: fd25cdb96d01ee806e4652a92ac14725c3ebe2aa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*******************************************************************************
 * Copyright (c) 2020 Red Hat, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *******************************************************************************/

package org.eclipse.m2e.jdt.tests;

import static org.junit.Assert.assertEquals;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;

import org.junit.Test;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;

import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.internal.preferences.MavenConfigurationImpl;
import org.eclipse.m2e.tests.common.AbstractMavenProjectTestCase;


public class JavaConfigurationTest extends AbstractMavenProjectTestCase {

  @Test
  public void testFileChangeUpdatesJDTSettings() throws CoreException, IOException, InterruptedException {
    ((MavenConfigurationImpl) MavenPlugin.getMavenConfiguration()).setAutomaticallyUpdateConfiguration(true);
    setAutoBuilding(true);
    File pomFileFS = new File(FileLocator.toFileURL(getClass().getResource("/projects/compilerSettings/pom.xml")).getFile());
    IProject project = importProject(pomFileFS.getAbsolutePath());
    waitForJobsToComplete();
    IJavaProject javaProject = (IJavaProject) project.getNature(JavaCore.NATURE_ID);
    assertEquals("1.8", javaProject.getOption(JavaCore.COMPILER_SOURCE, false));
    IFile pomFileWS = project.getFile("pom.xml");
    byte[] bytes = new byte[(int) pomFileFS.length()];
    try (InputStream stream = pomFileWS.getContents()) {
      stream.read(bytes);
    }
    String contents = new String(bytes);
    contents = contents.replaceAll("1\\.8", "11");
    pomFileWS.setContents(new ByteArrayInputStream(contents.getBytes()), true, false, null);
    waitForJobsToComplete();
    assertEquals("11", javaProject.getOption(JavaCore.COMPILER_SOURCE, false));
  }
}

Back to the top