Skip to content

Commit

Permalink
[eclipse] Make public the template of the pom file.
Browse files Browse the repository at this point in the history
This template of file could be used for created a Maven SARL project
from scratch.

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Aug 22, 2018
1 parent 689e7e7 commit c8b8175
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 15 deletions.
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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);
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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();
Expand All @@ -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();
}
Expand Down
Expand Up @@ -3,13 +3,14 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>%%GROUP_ID%%</groupId>
<artifactId>%%PROJECT_NAME%%</artifactId>
<version>0.0.1-SNAPSHOT</version>
<groupId>@GROUP_ID@</groupId>
<artifactId>@PROJECT_NAME@</artifactId>
<version>@PROJECT_VERSION@</version>

<properties>
<sarl.version>%%SARL_VERSION%%</sarl.version>
<compiler.level>%%JAVA_VERSION%%</compiler.level>
<project.build.sourceEncoding>%%FILE_ENCODING%%</project.build.sourceEncoding>
<sarl.version>@SARL_VERSION@</sarl.version>
<compiler.level>@JAVA_VERSION@</compiler.level>
<project.build.sourceEncoding>@FILE_ENCODING@</project.build.sourceEncoding>
</properties>

<dependencies>
Expand All @@ -22,12 +23,22 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${compiler.level}</source>
<target>${compiler.level}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>io.sarl.maven</groupId>
<artifactId>sarl-maven-plugin</artifactId>
<version>${sarl.version}</version>
<extensions>true</extensions>
<configuration>
<compiler>maven</compiler>
<source>${compiler.level}</source>
<target>${compiler.level}</target>
<encoding>${project.build.sourceEncoding}</encoding>
Expand Down
Expand Up @@ -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$
Expand Down
2 changes: 1 addition & 1 deletion main/targetplatform/io.sarl.lang.targetplatform.target
Expand Up @@ -36,7 +36,7 @@
</location>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<repository location="http://download.eclipse.org/modeling/tmf/xtext/updates/composite/latest/"/>
<unit id="org.eclipse.xtext.sdk.feature.group" version="2.15.0.v20180818-0209"/>
<unit id="org.eclipse.xtext.sdk.feature.group" version="2.15.0.v20180820-0209"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="aopalliance" version="1.0.0"/>
Expand Down

0 comments on commit c8b8175

Please sign in to comment.