From c8b8175122fa247caa607384340e911e0ee717f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Galland?= Date: Wed, 22 Aug 2018 14:01:51 +0200 Subject: [PATCH] [eclipse] Make public the template of the pom file. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This template of file could be used for created a Maven SARL project from scratch. Signed-off-by: Stéphane Galland --- .../newproject/NewSarlProjectWizard.java | 37 +++++++++++++++---- .../wizards/newproject/pom_template.xml | 23 +++++++++--- .../src/io/sarl/lang/SARLConfig.java | 4 ++ .../io.sarl.lang.targetplatform.target | 2 +- 4 files changed, 51 insertions(+), 15 deletions(-) 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 e815ea951c..43f6703021 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 @@ -87,6 +87,15 @@ */ public class NewSarlProjectWizard extends NewElementWizard implements IExecutableExtension { + /** The base name of the file that contains a template of a pom file. + * + * @since 0.8 + * @see #getPomTemplateLocation() + */ + public static final String POM_TEMPLATE_BASENAME = "pom_template.xml"; //$NON-NLS-1$ + + private static final String DEFAULT_MAVEN_PROJECT_VERSION = "0.0.1-SNAPSHOT"; //$NON-NLS-1$ + private MainProjectWizardPage firstPage; private BuildSettingWizardPage secondPage; @@ -99,7 +108,6 @@ public NewSarlProjectWizard() { this(null, null); } - /** Construct a new wizard for creating a SARL project. * * @param pageOne reference to the first page of the wizard. @@ -111,6 +119,18 @@ public NewSarlProjectWizard(MainProjectWizardPage pageOne, BuildSettingWizardPag this.secondPage = pageTwo; } + /** Replies the location of a template for the pom files. + * + * @return the location. Should be never {@code null}. + * @since 0.8 + * @see #POM_TEMPLATE_BASENAME + */ + public static URL getPomTemplateLocation() { + final URL url = Resources.getResource(NewSarlProjectWizard.class, POM_TEMPLATE_BASENAME); + assert url != null; + return url; + } + @Override public void init(IWorkbench workbench, IStructuredSelection currentSelection) { super.init(workbench, currentSelection); @@ -226,7 +246,7 @@ public boolean performFinish() { // Force SARL configuration SARLProjectConfigurator.configureSARLProject(newElement.getProject(), - false, false, new NullProgressMonitor()); + true, false, false, new NullProgressMonitor()); // Validate the SARL specific elements if (!validateSARLSpecificElements(newElement)) { @@ -271,7 +291,7 @@ public void run() { */ protected void createDefaultMavenPom(IJavaProject project, String compilerCompliance) { // Get the template resource. - final URL templateUrl = Resources.getResource(getClass(), "pom_template.xml"); //$NON-NLS-1$ + final URL templateUrl = getPomTemplateLocation(); if (templateUrl != null) { final String compliance = Strings.isNullOrEmpty(compilerCompliance) ? SARLVersion.MINIMAL_JDK_VERSION : compilerCompliance; final String groupId = getDefaultMavenGroupId(); @@ -280,11 +300,12 @@ protected void createDefaultMavenPom(IJavaProject project, String compilerCompli 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("%%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$ + 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(); } diff --git a/main/coreplugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/newproject/pom_template.xml b/main/coreplugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/newproject/pom_template.xml index 3cedf3bfcd..3d4a979148 100644 --- a/main/coreplugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/newproject/pom_template.xml +++ b/main/coreplugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/newproject/pom_template.xml @@ -3,13 +3,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - %%GROUP_ID%% - %%PROJECT_NAME%% - 0.0.1-SNAPSHOT + @GROUP_ID@ + @PROJECT_NAME@ + @PROJECT_VERSION@ + - %%SARL_VERSION%% - %%JAVA_VERSION%% - %%FILE_ENCODING%% + @SARL_VERSION@ + @JAVA_VERSION@ + @FILE_ENCODING@ @@ -22,12 +23,22 @@ + + org.apache.maven.plugins + maven-compiler-plugin + + ${compiler.level} + ${compiler.level} + ${project.build.sourceEncoding} + + io.sarl.maven sarl-maven-plugin ${sarl.version} true + maven ${compiler.level} ${compiler.level} ${project.build.sourceEncoding} diff --git a/main/coreplugins/io.sarl.lang/src/io/sarl/lang/SARLConfig.java b/main/coreplugins/io.sarl.lang/src/io/sarl/lang/SARLConfig.java index d4aa1f26da..19ea6769f0 100644 --- a/main/coreplugins/io.sarl.lang/src/io/sarl/lang/SARLConfig.java +++ b/main/coreplugins/io.sarl.lang/src/io/sarl/lang/SARLConfig.java @@ -81,6 +81,10 @@ public final class SARLConfig { */ public static final String FOLDER_BIN = "target/classes"; //$NON-NLS-1$ + /** Path of the binary test files. + */ + public static final String FOLDER_TEST_BIN = "target/test-classes"; //$NON-NLS-1$ + /** Path of the temporary files. */ public static final String FOLDER_TMP = "target/sarl-build"; //$NON-NLS-1$ diff --git a/main/targetplatform/io.sarl.lang.targetplatform.target b/main/targetplatform/io.sarl.lang.targetplatform.target index e82c96f932..076e0380ab 100644 --- a/main/targetplatform/io.sarl.lang.targetplatform.target +++ b/main/targetplatform/io.sarl.lang.targetplatform.target @@ -36,7 +36,7 @@ - +