diff --git a/main/coreplugins/io.sarl.eclipse/src/io/sarl/eclipse/natures/SARLProjectConfigurator.java b/main/coreplugins/io.sarl.eclipse/src/io/sarl/eclipse/natures/SARLProjectConfigurator.java index 0de55a493e..8e7ed4bb7b 100644 --- a/main/coreplugins/io.sarl.eclipse/src/io/sarl/eclipse/natures/SARLProjectConfigurator.java +++ b/main/coreplugins/io.sarl.eclipse/src/io/sarl/eclipse/natures/SARLProjectConfigurator.java @@ -279,9 +279,12 @@ public static void configureSARLProject(IProject project, boolean addNatures, outputFolder, testOutputFolder); // SARL specific configuration + final IFolder testGenerationFolderFolder = testGenerationFolder.get(); + final IPath testGenerationFolderPath = testGenerationFolderFolder == null ? null + : testGenerationFolderFolder.getProjectRelativePath(); SARLPreferences.setSpecificSARLConfigurationFor(project, generationFolder.get().getProjectRelativePath(), - testGenerationFolder.get().getProjectRelativePath()); + testGenerationFolderPath); subMonitor.worked(1); // Create the Java project @@ -338,27 +341,50 @@ private static void ensureSourceFolders(IProject project, boolean createFolders, final IFolder testOutputFolder = ensureOutputFolder(project, SARLConfig.FOLDER_TEST_BIN, true, createFolders, monitor.newChild(1)); if (sourcePaths != null) { - sourcePaths.set(new IFolder[] {sourceSarlFolder, sourceJavaFolder, resourcesFolder}); + assert sourceSarlFolder != null : "sourceSarlFolder must not be null"; + if (sourceJavaFolder != null) { + if (resourcesFolder != null) { + sourcePaths.set(new IFolder[] {sourceSarlFolder, sourceJavaFolder, resourcesFolder}); + } else { + sourcePaths.set(new IFolder[] {sourceSarlFolder, sourceJavaFolder}); + } + } else if (resourcesFolder != null) { + sourcePaths.set(new IFolder[] {sourceSarlFolder, resourcesFolder}); + } else { + sourcePaths.set(new IFolder[] {sourceSarlFolder}); + } } if (testSourcePaths != null) { - testSourcePaths.set(new IFolder[] {testSourceSarlFolder}); + if (testSourceSarlFolder != null) { + testSourcePaths.set(new IFolder[] {testSourceSarlFolder}); + } else { + testSourcePaths.set(new IFolder[] {}); + } } if (generationPaths != null) { + assert generationFolder != null : "generationFolder must not be null"; generationPaths.set(new IFolder[] {generationFolder}); } if (testGenerationPaths != null) { - testGenerationPaths.set(new IFolder[] {testGenerationFolder}); + if (testGenerationFolder != null) { + testGenerationPaths.set(new IFolder[] {testGenerationFolder}); + } else { + testGenerationPaths.set(new IFolder[] {}); + } } if (standardGenerationFolder != null) { + assert generationFolder != null : "generationFolder must not be null"; standardGenerationFolder.set(generationFolder); } - if (testingGenerationFolder != null) { + if (testingGenerationFolder != null && testGenerationFolder != null) { testingGenerationFolder.set(testGenerationFolder); } if (classOutput != null) { + assert outputFolder != null : "outputFolder must not be null"; classOutput.set(outputFolder); } if (testClassOutput != null) { + assert testOutputFolder != null : "testOutputFolder must not be null"; testClassOutput.set(testOutputFolder); } } diff --git a/main/coreplugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/newproject/NewSarlProjectWizard.java b/main/coreplugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/newproject/NewSarlProjectWizard.java index 7e4a5f59fc..6e67c38b37 100644 --- a/main/coreplugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/newproject/NewSarlProjectWizard.java +++ b/main/coreplugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/newproject/NewSarlProjectWizard.java @@ -290,37 +290,40 @@ public void run() { * @param compilerCompliance the Java version that is supported by the project. */ protected void createDefaultMavenPom(IJavaProject project, String compilerCompliance) { - // Get the template resource. - final URL templateUrl = getPomTemplateLocation(); - if (templateUrl != null) { - final String compliance = Strings.isNullOrEmpty(compilerCompliance) - ? SARLVersion.MINIMAL_JDK_VERSION_IN_SARL_PROJECT_CLASSPATH : compilerCompliance; - final String groupId = getDefaultMavenGroupId(); - // Read the template and do string replacement. - final StringBuilder content = new StringBuilder(); - try (BufferedReader reader = new BufferedReader(new InputStreamReader(templateUrl.openStream()))) { - String line = reader.readLine(); - while (line != null) { - line = line.replaceAll(Pattern.quote("@GROUP_ID@"), groupId); //$NON-NLS-1$ - line = line.replaceAll(Pattern.quote("@PROJECT_NAME@"), project.getElementName()); //$NON-NLS-1$ - line = line.replaceAll(Pattern.quote("@PROJECT_VERSION@"), DEFAULT_MAVEN_PROJECT_VERSION); //$NON-NLS-1$ - line = line.replaceAll(Pattern.quote("@SARL_VERSION@"), SARLVersion.SARL_RELEASE_VERSION_MAVEN); //$NON-NLS-1$ - line = line.replaceAll(Pattern.quote("@JAVA_VERSION@"), compliance); //$NON-NLS-1$ - line = line.replaceAll(Pattern.quote("@FILE_ENCODING@"), Charset.defaultCharset().displayName()); //$NON-NLS-1$ - content.append(line).append("\n"); //$NON-NLS-1$ - line = reader.readLine(); + final IFile pomFile = project.getProject().getFile("pom.xml"); //$NON-NLS-1$ + // Do not create the pom if already present. + if (!pomFile.exists()) { + // Get the template resource. + final URL templateUrl = getPomTemplateLocation(); + if (templateUrl != null) { + final String compliance = Strings.isNullOrEmpty(compilerCompliance) + ? SARLVersion.MINIMAL_JDK_VERSION_IN_SARL_PROJECT_CLASSPATH : compilerCompliance; + final String groupId = getDefaultMavenGroupId(); + // Read the template and do string replacement. + final StringBuilder content = new StringBuilder(); + try (BufferedReader reader = new BufferedReader(new InputStreamReader(templateUrl.openStream()))) { + String line = reader.readLine(); + while (line != null) { + line = line.replaceAll(Pattern.quote("@GROUP_ID@"), groupId); //$NON-NLS-1$ + line = line.replaceAll(Pattern.quote("@PROJECT_NAME@"), project.getElementName()); //$NON-NLS-1$ + line = line.replaceAll(Pattern.quote("@PROJECT_VERSION@"), DEFAULT_MAVEN_PROJECT_VERSION); //$NON-NLS-1$ + line = line.replaceAll(Pattern.quote("@SARL_VERSION@"), SARLVersion.SARL_RELEASE_VERSION_MAVEN); //$NON-NLS-1$ + line = line.replaceAll(Pattern.quote("@JAVA_VERSION@"), compliance); //$NON-NLS-1$ + line = line.replaceAll(Pattern.quote("@FILE_ENCODING@"), Charset.defaultCharset().displayName()); //$NON-NLS-1$ + content.append(line).append("\n"); //$NON-NLS-1$ + line = reader.readLine(); + } + } catch (IOException exception) { + throw new RuntimeIOException(exception); + } + // Write the pom + try (StringInputStream is = new StringInputStream(content.toString())) { + pomFile.create(is, true, new NullProgressMonitor()); + } catch (CoreException exception) { + throw new RuntimeException(exception); + } catch (IOException exception) { + throw new RuntimeIOException(exception); } - } catch (IOException exception) { - throw new RuntimeIOException(exception); - } - // Write the pom - final IFile pomFile = project.getProject().getFile("pom.xml"); //$NON-NLS-1$ - try (StringInputStream is = new StringInputStream(content.toString())) { - pomFile.create(is, true, new NullProgressMonitor()); - } catch (CoreException exception) { - throw new RuntimeException(exception); - } catch (IOException exception) { - throw new RuntimeIOException(exception); } } }