From edc927e3b4adbad521b6d190c9ddd851c7578723 Mon Sep 17 00:00:00 2001 From: Stephen Edwards Date: Fri, 15 May 2015 12:11:57 -0700 Subject: [PATCH 01/11] Remove duplicate release plugin. --- pom.xml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/pom.xml b/pom.xml index 4b90204..f439c0a 100644 --- a/pom.xml +++ b/pom.xml @@ -152,16 +152,6 @@ under the License. maven-javadoc-plugin 2.7 - - org.apache.maven.plugins - maven-release-plugin - 2.1 - - deploy - true - v@{project.version} - - org.apache.maven.plugins maven-remote-resources-plugin From af0cedd0fa34f969b7db24a02c9459f78e5439f0 Mon Sep 17 00:00:00 2001 From: Stephen Edwards Date: Sat, 16 May 2015 00:22:04 -0700 Subject: [PATCH 02/11] Put github repository id into a property. --- pom.xml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index f439c0a..ab7dbdd 100644 --- a/pom.xml +++ b/pom.xml @@ -51,9 +51,9 @@ under the License. - scm:git:git@github.com:sdedwards/m2e-nar.git - scm:git:git@github.com:sdedwards/m2e-nar.git - scm:git:git@github.com:sdedwards/m2e-nar.git + scm:git:git@github.com:${github.repo.id}.git + scm:git:git@github.com:${github.repo.id}.git + scm:git:git@github.com:${github.repo.id}.git @@ -70,6 +70,7 @@ under the License. UTF-8 0.22.0 http://download.eclipse.org/releases/kepler + sdedwards/m2e-nar @@ -240,7 +241,7 @@ under the License. First try at release v${project.version} v${project.version} - sdedwards/m2e-nar + ${github.repo.id} From 5f93509493cbbe8e29b1947cb63be2309a51e573 Mon Sep 17 00:00:00 2001 From: Stephen Edwards Date: Sat, 16 May 2015 23:41:12 -0700 Subject: [PATCH 03/11] Support for nar-maven-plugin-3.0.0. Add classesDirectory property. --- .../lifecycle-mapping-metadata.xml | 2 +- .../com/github/maven_nar/AbstractNarMojo.java | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/com.github.sdedwards.m2e-nar/lifecycle-mapping-metadata.xml b/com.github.sdedwards.m2e-nar/lifecycle-mapping-metadata.xml index 972ad0c..15d121b 100644 --- a/com.github.sdedwards.m2e-nar/lifecycle-mapping-metadata.xml +++ b/com.github.sdedwards.m2e-nar/lifecycle-mapping-metadata.xml @@ -31,7 +31,7 @@ com.github.maven-nar nar-maven-plugin - [3.0.0-rc1,) + [3.0.0-rc1],[3.0.0-rc-2],[3.0.0,) nar-validate nar-download diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/AbstractNarMojo.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/AbstractNarMojo.java index 0049bac..8a33dd9 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/AbstractNarMojo.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/AbstractNarMojo.java @@ -99,6 +99,12 @@ public abstract class AbstractNarMojo */ private File outputDirectory; + /** + * @parameter property="project.build.outputDirectory" + * @readonly + */ + protected File classesDirectory; + /** * Name of the output * - for jni default-value="${project.artifactId}-${project.version}" @@ -354,9 +360,15 @@ protected NarInfo getNarInfo() throws MojoExecutionException { { String groupId = getMavenProject().getGroupId(); String artifactId = getMavenProject().getArtifactId(); - - File propertiesDir = new File( getMavenProject().getBasedir(), "src/main/resources/META-INF/nar/" + groupId + "/" + artifactId ); - File propertiesFile = new File( propertiesDir, NarInfo.NAR_PROPERTIES ); + String path = "META-INF/nar/" + groupId + "/" + artifactId + "/" + NarInfo.NAR_PROPERTIES; + File propertiesFile = null; + if (classesDirectory != null) { + propertiesFile = new File( classesDirectory, path ); + } + // should not need to try and read from source. + if( propertiesFile == null || !propertiesFile.exists() ){ + propertiesFile = new File( getMavenProject().getBasedir(), "src/main/resources/" + path); + } narInfo = new NarInfo( groupId, artifactId, From 4c6277ac09e9b2dc135276c4c5fbc68ee5c13230 Mon Sep 17 00:00:00 2001 From: Stephen Edwards Date: Sun, 17 May 2015 02:07:58 -0700 Subject: [PATCH 04/11] Move up to nar-maven-plugin-3.0.0 for the integration tests. --- com.github.sdedwards.m2e-nar.tests/it/it-parent/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.github.sdedwards.m2e-nar.tests/it/it-parent/pom.xml b/com.github.sdedwards.m2e-nar.tests/it/it-parent/pom.xml index e1e85c4..422b714 100644 --- a/com.github.sdedwards.m2e-nar.tests/it/it-parent/pom.xml +++ b/com.github.sdedwards.m2e-nar.tests/it/it-parent/pom.xml @@ -37,7 +37,7 @@ under the License. com.github.maven-nar nar-maven-plugin - 3.0.0-rc1 + 3.0.0 From c5da189df88c713365f1684de0d756488f709d91 Mon Sep 17 00:00:00 2001 From: Stephen Edwards Date: Sun, 17 May 2015 02:08:42 -0700 Subject: [PATCH 05/11] nar-maven-plugin-3.0.0: test null javah includes --- com.github.sdedwards.m2e-nar.tests/it/it0003-jni/pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/com.github.sdedwards.m2e-nar.tests/it/it0003-jni/pom.xml b/com.github.sdedwards.m2e-nar.tests/it/it0003-jni/pom.xml index 685e23a..b9a3c7d 100644 --- a/com.github.sdedwards.m2e-nar.tests/it/it0003-jni/pom.xml +++ b/com.github.sdedwards.m2e-nar.tests/it/it0003-jni/pom.xml @@ -60,6 +60,11 @@ under the License. false + + + + + From a8294c8b8ca5138b11d5f9743d1cceb181abc30c Mon Sep 17 00:00:00 2001 From: Stephen Edwards Date: Sun, 17 May 2015 02:10:17 -0700 Subject: [PATCH 06/11] nar-maven-plugin-3.0.0: improve jni tests --- .../it/it0004-java-dep-jni/pom.xml | 12 +++++++ .../it/it0004-java-dep-jni/src/main/c/hello.c | 7 +++++ .../src/main/java/it0004/test/Hello.java | 31 +++++++++++++++++++ .../it0004/test/HelloWorldJavaDepJNITest.java | 5 +++ 4 files changed, 55 insertions(+) create mode 100644 com.github.sdedwards.m2e-nar.tests/it/it0004-java-dep-jni/src/main/c/hello.c create mode 100644 com.github.sdedwards.m2e-nar.tests/it/it0004-java-dep-jni/src/main/java/it0004/test/Hello.java diff --git a/com.github.sdedwards.m2e-nar.tests/it/it0004-java-dep-jni/pom.xml b/com.github.sdedwards.m2e-nar.tests/it/it0004-java-dep-jni/pom.xml index 1175dd0..3c3c296 100644 --- a/com.github.sdedwards.m2e-nar.tests/it/it0004-java-dep-jni/pom.xml +++ b/com.github.sdedwards.m2e-nar.tests/it/it0004-java-dep-jni/pom.xml @@ -48,6 +48,18 @@ under the License. com.github.maven-nar nar-maven-plugin true + + + true + + + + jni + it0004.test + false + + + diff --git a/com.github.sdedwards.m2e-nar.tests/it/it0004-java-dep-jni/src/main/c/hello.c b/com.github.sdedwards.m2e-nar.tests/it/it0004-java-dep-jni/src/main/c/hello.c new file mode 100644 index 0000000..6f1bd48 --- /dev/null +++ b/com.github.sdedwards.m2e-nar.tests/it/it0004-java-dep-jni/src/main/c/hello.c @@ -0,0 +1,7 @@ +#include "it0004_test_Hello.h" + +JNIEXPORT jbyte JNICALL Java_it0004_test_Hello_say + (JNIEnv *env, jclass clazz, jobject object) +{ + return (jbyte)13; +} diff --git a/com.github.sdedwards.m2e-nar.tests/it/it0004-java-dep-jni/src/main/java/it0004/test/Hello.java b/com.github.sdedwards.m2e-nar.tests/it/it0004-java-dep-jni/src/main/java/it0004/test/Hello.java new file mode 100644 index 0000000..2d6003f --- /dev/null +++ b/com.github.sdedwards.m2e-nar.tests/it/it0004-java-dep-jni/src/main/java/it0004/test/Hello.java @@ -0,0 +1,31 @@ +package it0004.test; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import it0003.HelloWorldJNI; + +public class Hello { + static + { + NarSystem.loadLibrary(); + } + + public native static byte say(HelloWorldJNI app); +} diff --git a/com.github.sdedwards.m2e-nar.tests/it/it0004-java-dep-jni/src/test/java/it0004/test/HelloWorldJavaDepJNITest.java b/com.github.sdedwards.m2e-nar.tests/it/it0004-java-dep-jni/src/test/java/it0004/test/HelloWorldJavaDepJNITest.java index e61551d..c521031 100644 --- a/com.github.sdedwards.m2e-nar.tests/it/it0004-java-dep-jni/src/test/java/it0004/test/HelloWorldJavaDepJNITest.java +++ b/com.github.sdedwards.m2e-nar.tests/it/it0004-java-dep-jni/src/test/java/it0004/test/HelloWorldJavaDepJNITest.java @@ -32,4 +32,9 @@ public class HelloWorldJavaDepJNITest Assert.assertEquals( "Hello NAR World!", app.sayHello() ); } + + @Test public final void testNativeMethod() + { + Assert.assertEquals(13, Hello.say(null)); + } } From fef56230ef6ea3f3b8848900d62d5587517ee317 Mon Sep 17 00:00:00 2001 From: Stephen Edwards Date: Sun, 17 May 2015 02:27:26 -0700 Subject: [PATCH 07/11] Be more relaxed about which versions are supported. --- com.github.sdedwards.m2e-nar/lifecycle-mapping-metadata.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.github.sdedwards.m2e-nar/lifecycle-mapping-metadata.xml b/com.github.sdedwards.m2e-nar/lifecycle-mapping-metadata.xml index 15d121b..2803b1b 100644 --- a/com.github.sdedwards.m2e-nar/lifecycle-mapping-metadata.xml +++ b/com.github.sdedwards.m2e-nar/lifecycle-mapping-metadata.xml @@ -31,7 +31,7 @@ com.github.maven-nar nar-maven-plugin - [3.0.0-rc1],[3.0.0-rc-2],[3.0.0,) + [3.0.0-rc1,),[3.0.0-rc-2,),[3.0.0,) nar-validate nar-download From e64eb05b1f8ce30b59c363827a47b1750488332c Mon Sep 17 00:00:00 2001 From: Stephen Edwards Date: Mon, 18 May 2015 09:50:52 -0700 Subject: [PATCH 08/11] Fix test name being null. --- .../m2e_nar/internal/NarExecutionBuilder.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/NarExecutionBuilder.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/NarExecutionBuilder.java index f845340..cae2862 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/NarExecutionBuilder.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/NarExecutionBuilder.java @@ -74,6 +74,8 @@ public NarExecution build(final String buildType) throws CoreException { ILibrary library = (ILibrary) iter.next(); NarBuildArtifact buildArtifact = buildArtifactSettings(library.getType(), buildType, library.linkCPP(), null); buildArtifact.setArtifactName(narCompileMojo.getOutput(library.getType())); + buildArtifact.setConfigName(CdtUtils.getConfigName( + mojoExecution, buildArtifact)); artifactSettings.add(buildArtifact); } } @@ -83,6 +85,8 @@ else if (NarExecution.TEST.equals(buildType)) { ITest test = (ITest) iter.next(); NarBuildArtifact buildArtifact = buildArtifactSettings(NarBuildArtifact.EXECUTABLE, buildType, true, test); buildArtifact.setArtifactName(test.getName()); + buildArtifact.setConfigName(CdtUtils.getTestConfigName( + mojoExecution, buildArtifact)); artifactSettings.add(buildArtifact); } } @@ -107,13 +111,6 @@ private NarBuildArtifact buildArtifactSettings(final String type, final String b NarBuildArtifact settings = new NarBuildArtifact(); settings.setType(type); - if (test == null) { - settings.setConfigName(CdtUtils.getConfigName( - mojoExecution, settings)); - } else { - settings.setConfigName(CdtUtils.getTestConfigName( - mojoExecution, settings)); - } List projectRefs = settings.getProjectReferences(); List narArtifacts = narCompileMojo.getNarArtifacts(); From c1ca07a26ba0a0553988c2283bb7f3ef8b437e45 Mon Sep 17 00:00:00 2001 From: Stephen Edwards Date: Mon, 18 May 2015 10:15:26 -0700 Subject: [PATCH 09/11] Fix dependency resolution. Only COMPILE, SYSTEM and PROVIDED should be used for the compile mojo. All artifacts are included for tests. --- .../maven_nar/AbstractDependencyMojo.java | 12 ++------- .../com/github/maven_nar/NarCompileMojo.java | 27 +++++++++---------- .../github/maven_nar/NarTestCompileMojo.java | 14 ++++++++++ 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/AbstractDependencyMojo.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/AbstractDependencyMojo.java index 7e2c728..b2dc844 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/AbstractDependencyMojo.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/AbstractDependencyMojo.java @@ -95,16 +95,8 @@ protected final List getRemoteRepositories() { return remoteArtifactRepositories; } - protected List getArtifacts() { - // Get all artifacts based on the dependency resolution of the mojo - Set artifacts = getMavenProject().getArtifacts(); - List returnArtifact = new ArrayList(); - for(Artifact a : artifacts) { - returnArtifact.add(a); - } - return returnArtifact; - } - + protected abstract List getArtifacts(); + /** * Returns dependencies which are dependent on NAR files (i.e. contain * NarInfo) diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarCompileMojo.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarCompileMojo.java index 29f0d25..a27b101 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarCompileMojo.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarCompileMojo.java @@ -22,19 +22,12 @@ */ package com.github.maven_nar; -import java.io.File; -import java.io.IOException; import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.LinkedList; import java.util.List; +import java.util.Set; +import org.apache.maven.artifact.Artifact; import org.apache.maven.execution.MavenSession; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.codehaus.plexus.util.FileUtils; -import org.codehaus.plexus.util.StringUtils; /** * Compiles native source files. @@ -48,12 +41,6 @@ */ public class NarCompileMojo extends AbstractCompileMojo { - /** - * @parameter default-value="${project.build.directory}/classes" - * @readonly - */ - private File outputDirectory; - /** * The current build session instance. * @@ -63,4 +50,14 @@ public class NarCompileMojo extends AbstractCompileMojo */ protected MavenSession session; + protected List getArtifacts() { + final Set artifacts = getMavenProject().getArtifacts(); + List returnArtifact = new ArrayList(); + for(Artifact a : artifacts) { + if (Artifact.SCOPE_COMPILE.equals(a.getScope()) || Artifact.SCOPE_PROVIDED.equals(a.getScope()) || Artifact.SCOPE_SYSTEM.equals(a.getScope())) { + returnArtifact.add(a); + } + } + return returnArtifact; + } } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarTestCompileMojo.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarTestCompileMojo.java index 3347a31..fbcee58 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarTestCompileMojo.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarTestCompileMojo.java @@ -22,6 +22,12 @@ */ package com.github.maven_nar; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; + /** * Compiles native test source files. * @@ -41,4 +47,12 @@ public class NarTestCompileMojo */ protected boolean skipNar; + protected List getArtifacts() { + final Set artifacts = getMavenProject().getArtifacts(); + List returnArtifact = new ArrayList(); + for(Artifact a : artifacts) { + returnArtifact.add(a); + } + return returnArtifact; + } } From 7b64e029c26f120476904a78f55f378724f8196e Mon Sep 17 00:00:00 2001 From: Stephen Edwards Date: Wed, 20 May 2015 23:23:04 -0700 Subject: [PATCH 10/11] Make sure test dependencies are unpacked. Not all versions of nar-maven-plugin have the nar-test-unpack goal so we must do it by running the nar-testCompile goal with an empty configuration element. This will unpack then compile nothing. --- .../lifecycle-mapping-metadata.xml | 1 + .../internal/CProjectConfigurator.java | 7 ++- .../m2e_nar/internal/MavenUtils.java | 10 +++- .../NarTestCompileBuildParticipant.java | 50 +++++++++++++++++++ 4 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/NarTestCompileBuildParticipant.java diff --git a/com.github.sdedwards.m2e-nar/lifecycle-mapping-metadata.xml b/com.github.sdedwards.m2e-nar/lifecycle-mapping-metadata.xml index 2803b1b..0852a49 100644 --- a/com.github.sdedwards.m2e-nar/lifecycle-mapping-metadata.xml +++ b/com.github.sdedwards.m2e-nar/lifecycle-mapping-metadata.xml @@ -48,6 +48,7 @@ nar-process-libraries nar-testDownload nar-testUnpack + nar-test-unpack nar-testCompile nar-test diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/CProjectConfigurator.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/CProjectConfigurator.java index 0225101..713304d 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/CProjectConfigurator.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/CProjectConfigurator.java @@ -187,10 +187,13 @@ public AbstractBuildParticipant getBuildParticipant( return null; } else if ("nar-testDownload".equals(goal)) { return new MojoExecutionBuildParticipant(execution, false, true); - } else if ("nar-testUnpack".equals(goal)) { + } else if (MavenUtils.isTestUnpack(goal)) { return new NarBuildParticipant(execution, false, true); } else if ("nar-testCompile".equals(goal)) { - return null; + // Note that this does not actually compile the tests, only unpacks + // test dependencies for compatibility with older versions of + // nar-maven-plugin + return new NarTestCompileBuildParticipant(execution, false, true); } else if ("nar-test".equals(goal)) { return null; } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/MavenUtils.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/MavenUtils.java index ff16675..d10ecbc 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/MavenUtils.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/MavenUtils.java @@ -71,6 +71,9 @@ public final class MavenUtils { public static String NAR_COMPILE_GOAL = "nar-compile"; public static String NAR_TESTCOMPILE_GOAL = "nar-testCompile"; + public static String NAR_TESTUNPACK_GOAL = "nar-testUnpack"; + public static String NAR_TEST_UNPACK_GOAL = "nar-test-unpack"; + private static final Logger logger = LoggerFactory.getLogger(MavenUtils.class); private static ClassRealm realm = null; @@ -131,7 +134,7 @@ public T call(IMavenExecutionContext context, }, monitor); } - public static T getConfiguredMojo(MavenSession session, + private static T getConfiguredMojo(MavenSession session, MojoExecution mojoExecution, Class asType, Log log) throws CoreException { MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); @@ -356,4 +359,9 @@ public static List buildTestCompileNarExecutions(final Configurato } return narExecutions; } + + public static boolean isTestUnpack(String goal) { + return NAR_TESTUNPACK_GOAL.equals(goal) || NAR_TEST_UNPACK_GOAL.equals(goal); + } + } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/NarTestCompileBuildParticipant.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/NarTestCompileBuildParticipant.java new file mode 100644 index 0000000..c969812 --- /dev/null +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/NarTestCompileBuildParticipant.java @@ -0,0 +1,50 @@ +/* + * #%L + * Maven Integration for Eclipse CDT + * %% + * Copyright (C) 2014 Stephen Edwards + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ +package com.github.sdedwards.m2e_nar.internal; + +import org.apache.maven.plugin.MojoExecution; +import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class NarTestCompileBuildParticipant extends NarBuildParticipant { + + private static final Logger logger = LoggerFactory.getLogger(CProjectConfigurator.class); + + public NarTestCompileBuildParticipant(MojoExecution execution, boolean runOnIncremental, boolean runOnConfiguration) { + super(new MojoExecution(execution.getMojoDescriptor(), execution.getExecutionId(), execution.getSource()) + , runOnIncremental, runOnConfiguration); + // Some versions of nar-maven-plugin don't have a nar-test-unpack goal + // this means the test artifacts won't be available to us. + // What we need to do is run the nar-testCompile goal without any tests its configuration + // in order to just unpack. + Xpp3Dom configuration = new Xpp3Dom(execution.getConfiguration()); + logger.info("Configuration before: " + configuration); + for (int i = 0; i < configuration.getChildCount(); ++i) { + if ("tests".equals(configuration.getChild(i).getName())) { + configuration.removeChild(i); + break; + } + } + logger.info("Configuration after: " + configuration); + getMojoExecution().setConfiguration(configuration); + } + +} From cdbb8efc291a14e41205d92a5480f50230105496 Mon Sep 17 00:00:00 2001 From: Stephen Edwards Date: Sat, 23 May 2015 04:57:57 -0700 Subject: [PATCH 11/11] Add Eclipse formatter settings. These are the Eclipse built in settings with the line length changed to 160 characters. The main source files have also been formatted. --- .../.settings/org.eclipse.jdt.core.prefs | 4 + .../src/com/github/maven_nar/AOL.java | 204 ++- .../github/maven_nar/AbstractCompileMojo.java | 940 +++++++------ .../maven_nar/AbstractDependencyMojo.java | 194 ++- .../github/maven_nar/AbstractNarLayout.java | 94 +- .../com/github/maven_nar/AbstractNarMojo.java | 6 +- .../github/maven_nar/AttachedNarArtifact.java | 95 +- .../src/com/github/maven_nar/C.java | 16 +- .../src/com/github/maven_nar/Compiler.java | 1002 +++++++------- .../src/com/github/maven_nar/Cpp.java | 16 +- .../github/maven_nar/EclipseNarLayout.java | 90 +- .../src/com/github/maven_nar/Executable.java | 7 +- .../src/com/github/maven_nar/Fortran.java | 16 +- .../src/com/github/maven_nar/ICompiler.java | 18 +- .../src/com/github/maven_nar/IDL.java | 5 +- .../src/com/github/maven_nar/ILibrary.java | 2 +- .../src/com/github/maven_nar/ILinker.java | 9 +- .../com/github/maven_nar/INarCompileMojo.java | 31 +- .../src/com/github/maven_nar/ITest.java | 3 +- .../src/com/github/maven_nar/Java.java | 144 +- .../src/com/github/maven_nar/Javah.java | 373 +++--- .../src/com/github/maven_nar/Lib.java | 21 +- .../src/com/github/maven_nar/Library.java | 267 ++-- .../src/com/github/maven_nar/Linker.java | 722 +++++----- .../src/com/github/maven_nar/Message.java | 16 +- .../src/com/github/maven_nar/NarArtifact.java | 62 +- .../com/github/maven_nar/NarCompileMojo.java | 20 +- .../com/github/maven_nar/NarConstants.java | 29 +- .../com/github/maven_nar/NarFileLayout.java | 40 +- .../com/github/maven_nar/NarFileLayout10.java | 53 +- .../src/com/github/maven_nar/NarInfo.java | 437 +++---- .../src/com/github/maven_nar/NarLayout.java | 132 +- .../src/com/github/maven_nar/NarLayout20.java | 296 ++--- .../src/com/github/maven_nar/NarLayout21.java | 370 +++--- .../src/com/github/maven_nar/NarLayout30.java | 523 ++++---- .../com/github/maven_nar/NarProperties.java | 89 +- .../github/maven_nar/NarTestCompileMojo.java | 34 +- .../src/com/github/maven_nar/NarUtil.java | 1163 +++++++---------- .../src/com/github/maven_nar/OS.java | 11 +- .../maven_nar/ProcessLibraryCommand.java | 94 +- .../src/com/github/maven_nar/Resource.java | 16 +- .../github/maven_nar/StringTextStream.java | 42 +- .../src/com/github/maven_nar/SysLib.java | 42 +- .../src/com/github/maven_nar/Test.java | 92 +- .../src/com/github/maven_nar/TextStream.java | 5 +- .../sdedwards/m2e_nar/MavenNarPlugin.java | 14 +- .../m2e_nar/internal/BuildPathManager.java | 31 +- .../internal/CProjectConfigurator.java | 149 +-- .../m2e_nar/internal/ConfiguratorContext.java | 2 +- .../internal/INarExecutionBuilder.java | 2 +- .../m2e_nar/internal/MavenUtils.java | 234 ++-- .../sdedwards/m2e_nar/internal/Messages.java | 54 +- .../m2e_nar/internal/NarBuildParticipant.java | 14 +- .../m2e_nar/internal/NarClassloader.java | 22 +- .../m2e_nar/internal/NarExecutionBuilder.java | 73 +- .../NarTestCompileBuildParticipant.java | 9 +- .../cdt/AbstractGnuCompilerSynchroniser.java | 53 +- .../cdt/AbstractGnuLinkerSynchroniser.java | 35 +- .../cdt/AbstractSettingsSynchroniser.java | 92 +- .../internal/cdt/CLinuxGccSynchroniser.java | 6 +- .../internal/cdt/CMacosxGccSynchroniser.java | 6 +- .../m2e_nar/internal/cdt/CdtUtils.java | 27 +- .../internal/cdt/CppLinuxGccSynchroniser.java | 6 +- .../cdt/CppMacosxGccSynchroniser.java | 6 +- .../cdt/GnuCCompilerSynchroniser.java | 30 +- .../internal/cdt/GnuCLinkerSynchroniser.java | 6 +- .../cdt/GnuCppCompilerSynchroniser.java | 31 +- .../cdt/GnuCppLinkerSynchroniser.java | 6 +- .../cdt/MacosxCLinkerSynchroniser.java | 6 +- .../cdt/MacosxCppLinkerSynchroniser.java | 6 +- .../m2e_nar/internal/cdt/OptionSetter.java | 34 +- .../internal/cdt/SettingsSynchroniser.java | 6 +- .../internal/cdt/SynchroniserFactory.java | 8 +- .../internal/model/NarBuildArtifact.java | 82 +- .../m2e_nar/internal/model/NarCompiler.java | 57 +- .../m2e_nar/internal/model/NarExecution.java | 20 +- .../m2e_nar/internal/model/NarLib.java | 14 +- .../m2e_nar/internal/model/NarLinker.java | 24 +- .../m2e_nar/internal/model/NarSysLib.java | 11 +- eclipse_formatter.xml | 291 +++++ 80 files changed, 4424 insertions(+), 4888 deletions(-) create mode 100644 eclipse_formatter.xml diff --git a/com.github.sdedwards.m2e-nar/.settings/org.eclipse.jdt.core.prefs b/com.github.sdedwards.m2e-nar/.settings/org.eclipse.jdt.core.prefs index 69c31cd..107056a 100644 --- a/com.github.sdedwards.m2e-nar/.settings/org.eclipse.jdt.core.prefs +++ b/com.github.sdedwards.m2e-nar/.settings/org.eclipse.jdt.core.prefs @@ -1,7 +1,11 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/AOL.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/AOL.java index a0efd5c..9c90f43 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/AOL.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/AOL.java @@ -23,111 +23,101 @@ * @author Mark Donszelmann * @version $Id$ */ -public class AOL -{ - - private String architecture; - - private String os; - - private String linkerName; - - private String suffix; - - // FIXME, need more complicated parsing for numbers as part of os. - public AOL( String aolWithSuffix ) - { - final int suffixIndex = 3; - final int linkerIndex = 2; - final int osIndex = 1; - final int architectureIndex = 0; - - String[] aolString = aolWithSuffix.split( "-", suffixIndex+1 ); - switch ( aolString.length ) - { - case suffixIndex+1: - suffix = aolString[suffixIndex]; - case linkerIndex+1: - linkerName = aolString[linkerIndex]; - case osIndex+1: - os = aolString[osIndex]; - case architectureIndex+1: - architecture = aolString[architectureIndex]; - break; - - default: - throw new IllegalArgumentException( "AOL '" + aolWithSuffix + "' cannot be parsed." ); - } - } - - public AOL( String aol, String aolSuffix ) - { - this(aol); - suffix = aolSuffix; - } - - public AOL( String architecture, String os, String linkerName, String suffix ) - { - this.architecture = architecture; - this.os = os; - this.linkerName = linkerName; - this.suffix = suffix; - } - - /** - * Returns an AOL string (arch-os-linker) to use as directory or file. - * @return dash separated AOL - */ - public final String toString() - { - String tempLinkerName = null; - if ( linkerName == null ) { - tempLinkerName = ""; - } else if ( linkerName.equals("g++") ) { - tempLinkerName = "-gpp"; - } else { - if ( linkerName.equals("g++") ) { - tempLinkerName = "-gpp"; - } else { - tempLinkerName = "-" + linkerName; - } - if ( suffix != null ) { - tempLinkerName += "-" + suffix; - } - } - - return architecture - + ((os == null) ? "" : "-" + os - + tempLinkerName); - } - - // FIXME, maybe change to something like isCompatible (AOL). - public final boolean hasLinker( String linker ) - { - return linkerName.equals(linker); - } - - /** - * Returns an AOL key (arch.os.linker) to search in the properties files. - * @return dot separated AOL - */ - public final String getKey() - { - String tempLinkerName = null; - if ( linkerName == null ) { - tempLinkerName = ""; - } else if ( linkerName.equals("g++") ) { - tempLinkerName = ".gpp"; - } else { - tempLinkerName = "." + linkerName; - } - - return architecture - + ((os == null) ? "" : "." + os - + tempLinkerName); - } - - final String getOS() { - return os; - } +public class AOL { + + private String architecture; + + private String os; + + private String linkerName; + + private String suffix; + + // FIXME, need more complicated parsing for numbers as part of os. + public AOL(String aolWithSuffix) { + final int suffixIndex = 3; + final int linkerIndex = 2; + final int osIndex = 1; + final int architectureIndex = 0; + + String[] aolString = aolWithSuffix.split("-", suffixIndex + 1); + switch (aolString.length) { + case suffixIndex + 1: + suffix = aolString[suffixIndex]; + case linkerIndex + 1: + linkerName = aolString[linkerIndex]; + case osIndex + 1: + os = aolString[osIndex]; + case architectureIndex + 1: + architecture = aolString[architectureIndex]; + break; + + default: + throw new IllegalArgumentException("AOL '" + aolWithSuffix + "' cannot be parsed."); + } + } + + public AOL(String aol, String aolSuffix) { + this(aol); + suffix = aolSuffix; + } + + public AOL(String architecture, String os, String linkerName, String suffix) { + this.architecture = architecture; + this.os = os; + this.linkerName = linkerName; + this.suffix = suffix; + } + + /** + * Returns an AOL string (arch-os-linker) to use as directory or file. + * + * @return dash separated AOL + */ + public final String toString() { + String tempLinkerName = null; + if (linkerName == null) { + tempLinkerName = ""; + } else if (linkerName.equals("g++")) { + tempLinkerName = "-gpp"; + } else { + if (linkerName.equals("g++")) { + tempLinkerName = "-gpp"; + } else { + tempLinkerName = "-" + linkerName; + } + if (suffix != null) { + tempLinkerName += "-" + suffix; + } + } + + return architecture + ((os == null) ? "" : "-" + os + tempLinkerName); + } + + // FIXME, maybe change to something like isCompatible (AOL). + public final boolean hasLinker(String linker) { + return linkerName.equals(linker); + } + + /** + * Returns an AOL key (arch.os.linker) to search in the properties files. + * + * @return dot separated AOL + */ + public final String getKey() { + String tempLinkerName = null; + if (linkerName == null) { + tempLinkerName = ""; + } else if (linkerName.equals("g++")) { + tempLinkerName = ".gpp"; + } else { + tempLinkerName = "." + linkerName; + } + + return architecture + ((os == null) ? "" : "." + os + tempLinkerName); + } + + final String getOS() { + return os; + } } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/AbstractCompileMojo.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/AbstractCompileMojo.java index a5cf627..694e35d 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/AbstractCompileMojo.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/AbstractCompileMojo.java @@ -38,503 +38,467 @@ /** * @author Mark Donszelmann */ -public abstract class AbstractCompileMojo - extends AbstractDependencyMojo implements INarCompileMojo -{ - - /** - * C++ Compiler - * - * @parameter default-value="" - */ - private Cpp cpp; - - /** - * C Compiler - * - * @parameter default-value="" - */ - private C c; - - /** - * Fortran Compiler - * - * @parameter default-value="" - */ - private Fortran fortran; - - /** - * Resource Compiler - * - * @parameter default-value="" - */ - private Resource resource; - - /** - * IDL Compiler - * - * @parameter default-value="" - */ - private IDL idl; - - /** - * Message Compiler - * - * @parameter default-value="" - */ - private Message message; - - /** - * By default NAR compile will attempt to compile using all known compilers against files in the directories specified by convention. - * This allows configuration to a reduced set, you will have to specify each compiler to use in the configuration. - * - * @parameter default-value="false" - */ - protected boolean onlySpecifiedCompilers; - - /** - * Maximum number of Cores/CPU's to use. 0 means unlimited. - * - * @parameter default-value="" - */ - private int maxCores = 0; - - - /** - * Fail on compilation/linking error. - * - * @parameter default-value="true" - * @required - */ - private boolean failOnError; - - /** - * Sets the type of runtime library, possible values "dynamic", "static". - * - * @parameter default-value="dynamic" - * @required - */ - private String runtime; - - /** - * Set use of libtool. If set to true, the "libtool " will be prepended to the command line for compatible - * processors. - * - * @parameter default-value="false" - * @required - */ - private boolean libtool; - - /** - * List of tests to create - * - * @parameter default-value="" - */ - private List tests; - - /** - * Java info for includes and linking - * - * @parameter default-value="" - */ - private Java java; - - /** - * Flag to cpptasks to indicate whether linker options should be decorated or not - * - * @parameter default-value="" - */ - protected boolean decorateLinkerOptions; - - private NarInfo narInfo; - - private List/* */dependencyLibOrder; - - public void setCpp(Cpp cpp) { - this.cpp = cpp; - cpp.setAbstractCompileMojo( this ); - } - - public void setC(C c) { - this.c = c; - c.setAbstractCompileMojo( this ); - } - - public void setFortran(Fortran fortran) { - this.fortran = fortran; - fortran.setAbstractCompileMojo( this ); - } - - public void setResource(Resource resource) { - this.resource = resource; - resource.setAbstractCompileMojo( this ); - } - - public void setIdl(IDL idl) { - this.idl = idl; - idl.setAbstractCompileMojo( this ); - } - - public void setMessage(Message message) { - this.message = message; - message.setAbstractCompileMojo( this ); - } - - public final C getC() - { - if ( c == null && !onlySpecifiedCompilers ) - { - setC( new C() ); - } - return c; - } - - public final Cpp getCpp() - { - if ( cpp == null && !onlySpecifiedCompilers ) - { - setCpp( new Cpp() ); - } - return cpp; - } - - public final Fortran getFortran() - { - if ( fortran == null && !onlySpecifiedCompilers ) - { - setFortran( new Fortran() ); - } - return fortran; - } - - protected final Resource getResource( ) - { - if ( resource == null && !onlySpecifiedCompilers ) - { - setResource( new Resource() ); - } - return resource; - } - - protected final IDL getIdl( ) - { - if ( idl == null && !onlySpecifiedCompilers ) - { - setIdl( new IDL() ); - } - return idl; - } - - protected final Message getMessage( ) - { - if ( message == null && !onlySpecifiedCompilers ) - { - setMessage( new Message() ); - } - return message; - } - - protected final int getMaxCores( AOL aol ) - throws MojoExecutionException - { - return getNarInfo().getProperty( aol, "maxCores", maxCores ); - } - - protected final boolean useLibtool( AOL aol ) - throws MojoExecutionException - { - return getNarInfo().getProperty( aol, "libtool", libtool ); - } - - protected final boolean failOnError( AOL aol ) - throws MojoExecutionException - { - return getNarInfo().getProperty( aol, "failOnError", failOnError ); - } - - protected final String getRuntime( AOL aol ) - throws MojoExecutionException - { - return getNarInfo().getProperty( aol, "runtime", runtime ); - } - - protected final String getOutput( AOL aol, String type ) - throws MojoExecutionException - { - return getNarInfo().getOutput( aol, getOutput( !ILibrary.EXECUTABLE.equals( type ) ) ); - } - - public final List getTests() - { - if ( tests == null ) - { - tests = Collections.EMPTY_LIST; - } - return tests; - } - - protected final Java getJava() - { - if ( java == null ) - { - java = new Java(); - } - java.setAbstractCompileMojo( this ); - return java; - } - - public final void setDependencyLibOrder( List/* */order ) - { - dependencyLibOrder = order; - } - - protected final List/* */getDependencyLibOrder() - { - return dependencyLibOrder; - } - - protected final NarInfo getNarInfo() - throws MojoExecutionException - { - if ( narInfo == null ) - { - String groupId = getMavenProject().getGroupId(); - String artifactId = getMavenProject().getArtifactId(); - - File propertiesDir = new File( getMavenProject().getBasedir(), "src/main/resources/META-INF/nar/" + groupId + "/" + artifactId ); - File propertiesFile = new File( propertiesDir, NarInfo.NAR_PROPERTIES ); - - narInfo = new NarInfo( - groupId, artifactId, - getMavenProject().getVersion(), - getLog(), - propertiesFile ); - } - return narInfo; - } - - public Linker getLinker() { - Linker linker = super.getLinker(); - linker.setAbstractCompileMojo(this); - return linker; - } - - protected List/* */ getDependenciesToLink(String type) throws MojoExecutionException, MojoFailureException { - List dependencies = new LinkedList(); +public abstract class AbstractCompileMojo extends AbstractDependencyMojo implements INarCompileMojo { + + /** + * C++ Compiler + * + * @parameter default-value="" + */ + private Cpp cpp; + + /** + * C Compiler + * + * @parameter default-value="" + */ + private C c; + + /** + * Fortran Compiler + * + * @parameter default-value="" + */ + private Fortran fortran; + + /** + * Resource Compiler + * + * @parameter default-value="" + */ + private Resource resource; + + /** + * IDL Compiler + * + * @parameter default-value="" + */ + private IDL idl; + + /** + * Message Compiler + * + * @parameter default-value="" + */ + private Message message; + + /** + * By default NAR compile will attempt to compile using all known compilers + * against files in the directories specified by convention. This allows + * configuration to a reduced set, you will have to specify each compiler to + * use in the configuration. + * + * @parameter default-value="false" + */ + protected boolean onlySpecifiedCompilers; + + /** + * Maximum number of Cores/CPU's to use. 0 means unlimited. + * + * @parameter default-value="" + */ + private int maxCores = 0; + + /** + * Fail on compilation/linking error. + * + * @parameter default-value="true" + * @required + */ + private boolean failOnError; + + /** + * Sets the type of runtime library, possible values "dynamic", "static". + * + * @parameter default-value="dynamic" + * @required + */ + private String runtime; + + /** + * Set use of libtool. If set to true, the "libtool " will be prepended to + * the command line for compatible processors. + * + * @parameter default-value="false" + * @required + */ + private boolean libtool; + + /** + * List of tests to create + * + * @parameter default-value="" + */ + private List tests; + + /** + * Java info for includes and linking + * + * @parameter default-value="" + */ + private Java java; + + /** + * Flag to cpptasks to indicate whether linker options should be decorated + * or not + * + * @parameter default-value="" + */ + protected boolean decorateLinkerOptions; + + private NarInfo narInfo; + + private List/* */dependencyLibOrder; + + public void setCpp(Cpp cpp) { + this.cpp = cpp; + cpp.setAbstractCompileMojo(this); + } + + public void setC(C c) { + this.c = c; + c.setAbstractCompileMojo(this); + } + + public void setFortran(Fortran fortran) { + this.fortran = fortran; + fortran.setAbstractCompileMojo(this); + } + + public void setResource(Resource resource) { + this.resource = resource; + resource.setAbstractCompileMojo(this); + } + + public void setIdl(IDL idl) { + this.idl = idl; + idl.setAbstractCompileMojo(this); + } + + public void setMessage(Message message) { + this.message = message; + message.setAbstractCompileMojo(this); + } + + public final C getC() { + if (c == null && !onlySpecifiedCompilers) { + setC(new C()); + } + return c; + } + + public final Cpp getCpp() { + if (cpp == null && !onlySpecifiedCompilers) { + setCpp(new Cpp()); + } + return cpp; + } + + public final Fortran getFortran() { + if (fortran == null && !onlySpecifiedCompilers) { + setFortran(new Fortran()); + } + return fortran; + } + + protected final Resource getResource() { + if (resource == null && !onlySpecifiedCompilers) { + setResource(new Resource()); + } + return resource; + } + + protected final IDL getIdl() { + if (idl == null && !onlySpecifiedCompilers) { + setIdl(new IDL()); + } + return idl; + } + + protected final Message getMessage() { + if (message == null && !onlySpecifiedCompilers) { + setMessage(new Message()); + } + return message; + } + + protected final int getMaxCores(AOL aol) throws MojoExecutionException { + return getNarInfo().getProperty(aol, "maxCores", maxCores); + } + + protected final boolean useLibtool(AOL aol) throws MojoExecutionException { + return getNarInfo().getProperty(aol, "libtool", libtool); + } + + protected final boolean failOnError(AOL aol) throws MojoExecutionException { + return getNarInfo().getProperty(aol, "failOnError", failOnError); + } + + protected final String getRuntime(AOL aol) throws MojoExecutionException { + return getNarInfo().getProperty(aol, "runtime", runtime); + } + + protected final String getOutput(AOL aol, String type) throws MojoExecutionException { + return getNarInfo().getOutput(aol, getOutput(!ILibrary.EXECUTABLE.equals(type))); + } + + public final List getTests() { + if (tests == null) { + tests = Collections.EMPTY_LIST; + } + return tests; + } + + protected final Java getJava() { + if (java == null) { + java = new Java(); + } + java.setAbstractCompileMojo(this); + return java; + } + + public final void setDependencyLibOrder(List/* */order) { + dependencyLibOrder = order; + } + + protected final List/* */getDependencyLibOrder() { + return dependencyLibOrder; + } + + protected final NarInfo getNarInfo() throws MojoExecutionException { + if (narInfo == null) { + String groupId = getMavenProject().getGroupId(); + String artifactId = getMavenProject().getArtifactId(); + + File propertiesDir = new File(getMavenProject().getBasedir(), "src/main/resources/META-INF/nar/" + groupId + "/" + artifactId); + File propertiesFile = new File(propertiesDir, NarInfo.NAR_PROPERTIES); + + narInfo = new NarInfo(groupId, artifactId, getMavenProject().getVersion(), getLog(), propertiesFile); + } + return narInfo; + } + + public Linker getLinker() { + Linker linker = super.getLinker(); + linker.setAbstractCompileMojo(this); + return linker; + } + + protected List/* */getDependenciesToLink(String type) throws MojoExecutionException, MojoFailureException { + List dependencies = new LinkedList(); // FIXME: what about PLUGIN and STATIC, depending on STATIC, should we - // not add all libraries, see NARPLUGIN-96 - if ( type.equals( ILibrary.SHARED ) || type.equals( ILibrary.JNI ) || type.equals( ILibrary.EXECUTABLE ) ) - { - List depLibOrder = getDependencyLibOrder(); - List depLibs = getNarArtifacts(); - - // reorder the libraries that come from the nar dependencies - // to comply with the order specified by the user - if ( ( depLibOrder != null ) && !depLibOrder.isEmpty() ) - { - List tmp = new LinkedList(); - - for ( Iterator i = depLibOrder.iterator(); i.hasNext(); ) - { - String depToOrderName = (String) i.next(); - - for ( Iterator j = depLibs.iterator(); j.hasNext(); ) - { - NarArtifact dep = (NarArtifact) j.next(); - String depName = dep.getGroupId() + ":" + dep.getArtifactId(); - - if (depName.equals(depToOrderName)) - { - tmp.add(dep); - j.remove(); - } - } - } - - tmp.addAll(depLibs); - depLibs = tmp; - } - for ( Iterator i = depLibs.iterator(); i.hasNext(); ) - { - NarArtifact dependency = (NarArtifact) i.next(); - - // FIXME no handling of "local" - - // FIXME, no way to override this at this stage - String binding = dependency.getNarInfo().getBinding( getAOL(), ILibrary.NONE ); - getLog().debug("Using Binding: " + binding); - - if ( !binding.equals( ILibrary.JNI ) && !binding.equals( ILibrary.NONE ) && !binding.equals( ILibrary.EXECUTABLE) ) - { - dependencies.add(dependency); - } - } - } - return dependencies; - } - + // not add all libraries, see NARPLUGIN-96 + if (type.equals(ILibrary.SHARED) || type.equals(ILibrary.JNI) || type.equals(ILibrary.EXECUTABLE)) { + List depLibOrder = getDependencyLibOrder(); + List depLibs = getNarArtifacts(); + + // reorder the libraries that come from the nar dependencies + // to comply with the order specified by the user + if ((depLibOrder != null) && !depLibOrder.isEmpty()) { + List tmp = new LinkedList(); + + for (Iterator i = depLibOrder.iterator(); i.hasNext();) { + String depToOrderName = (String) i.next(); + + for (Iterator j = depLibs.iterator(); j.hasNext();) { + NarArtifact dep = (NarArtifact) j.next(); + String depName = dep.getGroupId() + ":" + dep.getArtifactId(); + + if (depName.equals(depToOrderName)) { + tmp.add(dep); + j.remove(); + } + } + } + + tmp.addAll(depLibs); + depLibs = tmp; + } + for (Iterator i = depLibs.iterator(); i.hasNext();) { + NarArtifact dependency = (NarArtifact) i.next(); + + // FIXME no handling of "local" + + // FIXME, no way to override this at this stage + String binding = dependency.getNarInfo().getBinding(getAOL(), ILibrary.NONE); + getLog().debug("Using Binding: " + binding); + + if (!binding.equals(ILibrary.JNI) && !binding.equals(ILibrary.NONE) && !binding.equals(ILibrary.EXECUTABLE)) { + dependencies.add(dependency); + } + } + } + return dependencies; + } + protected File getLibraryPath(NarArtifact dependency) throws MojoFailureException, MojoExecutionException { - String binding = dependency.getNarInfo().getBinding( getAOL(), ILibrary.NONE ); - AOL aol = getAOL(); - aol = dependency.getNarInfo().getAOL(getAOL()); - getLog().debug("Using Library AOL: " + aol.toString()); - - File unpackDirectory = getUnpackDirectory(dependency); - NarLayout layout = dependency.getNarLayout(); - - File dir = - layout.getLibDirectory( unpackDirectory, dependency, aol.toString(), binding ); - return dir; - } - - /* (non-Javadoc) + String binding = dependency.getNarInfo().getBinding(getAOL(), ILibrary.NONE); + AOL aol = getAOL(); + aol = dependency.getNarInfo().getAOL(getAOL()); + getLog().debug("Using Library AOL: " + aol.toString()); + + File unpackDirectory = getUnpackDirectory(dependency); + NarLayout layout = dependency.getNarLayout(); + + File dir = layout.getLibDirectory(unpackDirectory, dependency, aol.toString(), binding); + return dir; + } + + /* + * (non-Javadoc) + * * @see com.github.maven_nar.INarCompileMojo#getJavahIncludePaths() */ - public List/* */ getJavahIncludePaths() { - List includePaths = new ArrayList(); - boolean isJNI = false; - for (Library library : libraries) { - if (Library.JNI.equals(library.getType())) { - isJNI = true; - } - } - if (isJNI) - { - // add javah include path - File jniDirectory = getJavah().getJniDirectory(); - includePaths.add(jniDirectory.getPath()); - } - return includePaths; - } - - /* (non-Javadoc) + public List/* */getJavahIncludePaths() { + List includePaths = new ArrayList(); + boolean isJNI = false; + for (Library library : libraries) { + if (Library.JNI.equals(library.getType())) { + isJNI = true; + } + } + if (isJNI) { + // add javah include path + File jniDirectory = getJavah().getJniDirectory(); + includePaths.add(jniDirectory.getPath()); + } + return includePaths; + } + + /* + * (non-Javadoc) + * * @see com.github.maven_nar.INarCompileMojo#getJavaIncludePaths() */ - public List/* */ getJavaIncludePaths() throws MojoExecutionException, MojoFailureException { - for (Library library : libraries) { - if (Library.JNI.equals(library.getType())) { - getJava().setInclude(true); - } - } - return getJava().getIncludePaths(); - } - - /* (non-Javadoc) + public List/* */getJavaIncludePaths() throws MojoExecutionException, MojoFailureException { + for (Library library : libraries) { + if (Library.JNI.equals(library.getType())) { + getJava().setInclude(true); + } + } + return getJava().getIncludePaths(); + } + + /* + * (non-Javadoc) + * * @see com.github.maven_nar.INarCompileMojo#getDependencyIncludePaths() */ - public List/* */ getDependencyIncludePaths() throws MojoExecutionException, MojoFailureException { - List includePaths = new ArrayList(); - // add dependency include paths - for ( Iterator i = getNarArtifacts().iterator(); i.hasNext(); ) - { - // FIXME, handle multiple includes from one NAR - NarArtifact narDependency = (NarArtifact) i.next(); - String binding = narDependency.getNarInfo().getBinding(getAOL(), ILibrary.STATIC); - getLog().debug( "Looking for " + narDependency + " found binding " + binding); - if ( !binding.equals(ILibrary.JNI ) ) - { - File unpackDirectory = getUnpackDirectory(narDependency); - NarLayout layout = narDependency.getNarLayout(); - List includes = - layout.getIncludeDirectories( unpackDirectory, narDependency ); - includePaths.addAll(includes); - } - } - return includePaths; - } - - /* (non-Javadoc) - * @see com.github.maven_nar.INarCompileMojo#getDependencyLibs(java.lang.String) + public List/* */getDependencyIncludePaths() throws MojoExecutionException, MojoFailureException { + List includePaths = new ArrayList(); + // add dependency include paths + for (Iterator i = getNarArtifacts().iterator(); i.hasNext();) { + // FIXME, handle multiple includes from one NAR + NarArtifact narDependency = (NarArtifact) i.next(); + String binding = narDependency.getNarInfo().getBinding(getAOL(), ILibrary.STATIC); + getLog().debug("Looking for " + narDependency + " found binding " + binding); + if (!binding.equals(ILibrary.JNI)) { + File unpackDirectory = getUnpackDirectory(narDependency); + NarLayout layout = narDependency.getNarLayout(); + List includes = layout.getIncludeDirectories(unpackDirectory, narDependency); + includePaths.addAll(includes); + } + } + return includePaths; + } + + /* + * (non-Javadoc) + * + * @see + * com.github.maven_nar.INarCompileMojo#getDependencyLibs(java.lang.String) */ - public List/* */ getDependencyLibs(final String type, final ITest test) throws MojoExecutionException, MojoFailureException { - List libraries = new ArrayList(); - if (test != null) { - // Add the library of this package if it exists - final String linkType = test.getLink(); - getLog().debug("Test: " + test.getName() + ", link: " + linkType); - boolean found = false; - for (Library lib : getLibraries()) { - if (linkType.equals(lib.getType())) { - found = true; - break; - } - } - if (found) { - getLog().debug("Adding " + linkType + " library for test " + test.getName()); - final File dir = new File(getMavenProject().getBasedir(), CdtUtils.DEFAULT_CONFIG_NAME_PREFIX + test.getLink()); - final Lib library = new Lib(); - library.setName(getMavenProject().getArtifactId()); - library.setDirectory(dir); - library.setType(linkType); - libraries.add(library); - } - } - for ( Iterator i = getDependenciesToLink(type).iterator(); i.hasNext(); ) - { - NarArtifact dependency = (NarArtifact) i.next(); - - // FIXME, no way to override - String binding = dependency.getNarInfo().getBinding( getAOL(), ILibrary.NONE ); - String libs = dependency.getNarInfo().getLibs(getAOL()); - if ( ( libs != null ) && !libs.equals( "" ) ) - { - File dir = getLibraryPath(dependency); - String[] libArray = new NarUtil.StringArrayBuilder(libs).getValue(); - for (int j = 0; j < libArray.length; ++j) { - Lib library = new Lib(); - library.setName(libArray[j]); - library.setDirectory(dir); - library.setType(binding); - libraries.add(library); - } - } - } - return libraries; - } - - /* (non-Javadoc) - * @see com.github.maven_nar.INarCompileMojo#getDependencySysLibs(java.lang.String) + public List/* */getDependencyLibs(final String type, final ITest test) throws MojoExecutionException, MojoFailureException { + List libraries = new ArrayList(); + if (test != null) { + // Add the library of this package if it exists + final String linkType = test.getLink(); + getLog().debug("Test: " + test.getName() + ", link: " + linkType); + boolean found = false; + for (Library lib : getLibraries()) { + if (linkType.equals(lib.getType())) { + found = true; + break; + } + } + if (found) { + getLog().debug("Adding " + linkType + " library for test " + test.getName()); + final File dir = new File(getMavenProject().getBasedir(), CdtUtils.DEFAULT_CONFIG_NAME_PREFIX + test.getLink()); + final Lib library = new Lib(); + library.setName(getMavenProject().getArtifactId()); + library.setDirectory(dir); + library.setType(linkType); + libraries.add(library); + } + } + for (Iterator i = getDependenciesToLink(type).iterator(); i.hasNext();) { + NarArtifact dependency = (NarArtifact) i.next(); + + // FIXME, no way to override + String binding = dependency.getNarInfo().getBinding(getAOL(), ILibrary.NONE); + String libs = dependency.getNarInfo().getLibs(getAOL()); + if ((libs != null) && !libs.equals("")) { + File dir = getLibraryPath(dependency); + String[] libArray = new NarUtil.StringArrayBuilder(libs).getValue(); + for (int j = 0; j < libArray.length; ++j) { + Lib library = new Lib(); + library.setName(libArray[j]); + library.setDirectory(dir); + library.setType(binding); + libraries.add(library); + } + } + } + return libraries; + } + + /* + * (non-Javadoc) + * + * @see + * com.github.maven_nar.INarCompileMojo#getDependencySysLibs(java.lang.String + * ) */ - public List/* */ getDependencySysLibs(final String type) throws MojoExecutionException, MojoFailureException { - List libraries = new ArrayList(); - for ( Iterator i = getDependenciesToLink(type).iterator(); i.hasNext(); ) - { - NarArtifact dependency = (NarArtifact) i.next(); - - String sysLibs = dependency.getNarInfo().getSysLibs( getAOL() ); - if ( ( sysLibs != null ) && !sysLibs.equals( "" ) ) - { - String[] sysLibArray = new NarUtil.StringArrayBuilder(sysLibs).getValue(); - for (int j = 0; j < sysLibArray.length; ++j) { - SysLib library = new SysLib(); - library.setName(sysLibArray[j]); - library.setType(null); - libraries.add(library); - } - } - } - return libraries; - } - - /* (non-Javadoc) - * @see com.github.maven_nar.INarCompileMojo#getDependencyOptions(java.lang.String) + public List/* */getDependencySysLibs(final String type) throws MojoExecutionException, MojoFailureException { + List libraries = new ArrayList(); + for (Iterator i = getDependenciesToLink(type).iterator(); i.hasNext();) { + NarArtifact dependency = (NarArtifact) i.next(); + + String sysLibs = dependency.getNarInfo().getSysLibs(getAOL()); + if ((sysLibs != null) && !sysLibs.equals("")) { + String[] sysLibArray = new NarUtil.StringArrayBuilder(sysLibs).getValue(); + for (int j = 0; j < sysLibArray.length; ++j) { + SysLib library = new SysLib(); + library.setName(sysLibArray[j]); + library.setType(null); + libraries.add(library); + } + } + } + return libraries; + } + + /* + * (non-Javadoc) + * + * @see + * com.github.maven_nar.INarCompileMojo#getDependencyOptions(java.lang.String + * ) */ - public List/* */ getDependencyOptions(final String type) throws MojoExecutionException, MojoFailureException { - List optionList = new ArrayList(); - for ( Iterator i = getDependenciesToLink(type).iterator(); i.hasNext(); ) - { - NarArtifact dependency = (NarArtifact) i.next(); - - String options = dependency.getNarInfo().getOptions( getAOL() ); - if ( ( options != null ) && !options.equals( "" ) ) - { - optionList.add(options); - } - } - return optionList; - } - - public String getOutput(final String type) throws MojoFailureException, MojoExecutionException { - return getOutput(getAOL(), type); - } + public List/* */getDependencyOptions(final String type) throws MojoExecutionException, MojoFailureException { + List optionList = new ArrayList(); + for (Iterator i = getDependenciesToLink(type).iterator(); i.hasNext();) { + NarArtifact dependency = (NarArtifact) i.next(); + + String options = dependency.getNarInfo().getOptions(getAOL()); + if ((options != null) && !options.equals("")) { + optionList.add(options); + } + } + return optionList; + } + + public String getOutput(final String type) throws MojoFailureException, MojoExecutionException { + return getOutput(getAOL(), type); + } } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/AbstractDependencyMojo.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/AbstractDependencyMojo.java index b2dc844..c399936 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/AbstractDependencyMojo.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/AbstractDependencyMojo.java @@ -78,13 +78,13 @@ public abstract class AbstractDependencyMojo extends AbstractNarMojo { protected List remoteArtifactRepositories; /** - * The plugin remote repositories declared in the pom. - * - * @parameter default-value="${project.pluginArtifactRepositories}" - * @since 2.2 - */ - // private List remotePluginRepositories; - + * The plugin remote repositories declared in the pom. + * + * @parameter default-value="${project.pluginArtifactRepositories}" + * @since 2.2 + */ + // private List remotePluginRepositories; + protected List narDependencies = null; protected final ArtifactRepository getLocalRepository() { @@ -95,8 +95,8 @@ protected final List getRemoteRepositories() { return remoteArtifactRepositories; } - protected abstract List getArtifacts(); - + protected abstract List getArtifacts(); + /** * Returns dependencies which are dependent on NAR files (i.e. contain * NarInfo) @@ -105,9 +105,8 @@ public final List getNarArtifacts() { return narDependencies; } - private final NarInfo getNarInfo(Artifact dependency) - throws MojoExecutionException { - + private final NarInfo getNarInfo(Artifact dependency) throws MojoExecutionException { + File file = dependency.getFile(); if (!file.exists()) { getLog().debug("Dependency nar file does not exist: " + file); @@ -120,13 +119,9 @@ private final NarInfo getNarInfo(Artifact dependency) } try { - NarInfo info = new NarInfo(dependency.getGroupId(), - dependency.getArtifactId(), dependency.getBaseVersion(), - getLog()); + NarInfo info = new NarInfo(dependency.getGroupId(), dependency.getArtifactId(), dependency.getBaseVersion(), getLog()); if (!info.exists(file)) { - getLog().debug( - "Dependency nar file does not contain this artifact: " - + file); + getLog().debug("Dependency nar file does not contain this artifact: " + file); return null; } info.read(file); @@ -136,51 +131,46 @@ private final NarInfo getNarInfo(Artifact dependency) } } - private final NarInfo getNarInfo(Artifact dependency, EclipseNarLayout layout) - throws MojoExecutionException, MojoFailureException { - NarInfo narInfo = new NarInfo(dependency.getGroupId(), - dependency.getArtifactId(), dependency.getBaseVersion(), - getLog()); + private final NarInfo getNarInfo(Artifact dependency, EclipseNarLayout layout) throws MojoExecutionException, MojoFailureException { + NarInfo narInfo = new NarInfo(dependency.getGroupId(), dependency.getArtifactId(), dependency.getBaseVersion(), getLog()); AOL aol = getAOL(); - for (String type : layout.getConfigurations() ){ - - if ( ( narInfo.getOutput( aol, null ) == null ) ) - { - narInfo.setOutput( aol, layout.getArtifactName(type) ); - } - - // We prefer shared to jni/executable/static/none, - if ( type.equals( ILibrary.SHARED ) ) // overwrite whatever we had - { - narInfo.setBinding( aol, type ); - narInfo.setBinding( null, type ); - } - else - { - // if the binding is already set, then don't write it for jni/executable/static/none. - if ( ( narInfo.getBinding( aol, null ) == null ) ) - { - narInfo.setBinding( aol, type ); - } - if ( ( narInfo.getBinding( null, null ) == null ) ) - { - narInfo.setBinding( null, type ); - } - } - - } - - // setting this first stops the per type config because getOutput check for aol defaults to this generic one... - if ( narInfo.getOutput( null, null ) == null ) - { - narInfo.setOutput( null, dependency.getArtifactId() ); - } + for (String type : layout.getConfigurations()) { + + if ((narInfo.getOutput(aol, null) == null)) { + narInfo.setOutput(aol, layout.getArtifactName(type)); + } + + // We prefer shared to jni/executable/static/none, + if (type.equals(ILibrary.SHARED)) // overwrite whatever we had + { + narInfo.setBinding(aol, type); + narInfo.setBinding(null, type); + } else { + // if the binding is already set, then don't write it for + // jni/executable/static/none. + if ((narInfo.getBinding(aol, null) == null)) { + narInfo.setBinding(aol, type); + } + if ((narInfo.getBinding(null, null) == null)) { + narInfo.setBinding(null, type); + } + } + + } + + // setting this first stops the per type config because getOutput check + // for aol defaults to this generic one... + if (narInfo.getOutput(null, null) == null) { + narInfo.setOutput(null, dependency.getArtifactId()); + } return narInfo; } - - public final List getAllAttachedNarArtifacts( - List narArtifacts/*, Library library*/) - throws MojoExecutionException, MojoFailureException { + + public final List getAllAttachedNarArtifacts(List narArtifacts/* + * , + * Library + * library + */) throws MojoExecutionException, MojoFailureException { List artifactList = new ArrayList(); for (Iterator i = narArtifacts.iterator(); i.hasNext();) { NarArtifact dependency = i.next(); @@ -190,28 +180,27 @@ public final List getAllAttachedNarArtifacts( if (dependency.getNarInfo() == null) { continue; } - - String binding = getBinding(/*library,*/ dependency); + + String binding = getBinding(/* library, */dependency); // TODO: dependency.getFile(); find out what the stored pom says // about this - what nars should exist, what layout are they // using... artifactList.addAll(getAttachedNarArtifacts(dependency, /* library. */ getAOL(), binding)); - artifactList.addAll(getAttachedNarArtifacts(dependency, null, - NarConstants.NAR_NO_ARCH)); + artifactList.addAll(getAttachedNarArtifacts(dependency, null, NarConstants.NAR_NO_ARCH)); } return artifactList; } - protected String getBinding(/*Library library,*/ NarArtifact dependency) - throws MojoFailureException, MojoExecutionException { + protected String getBinding(/* Library library, */NarArtifact dependency) throws MojoFailureException, MojoExecutionException { // how does this project specify the dependency is used // - library.getLinker().getLibs(); // - if it is specified but the artifact is not available should fail. - // otherwise how does the artifact specify it should be used by default + // otherwise how does the artifact specify it should be used by default // - // - what is the preference for this type of library to use (shared - shared, static - static...) + // - what is the preference for this type of library to use (shared - + // shared, static - static...) // library.getType() String binding = dependency.getNarInfo().getBinding( @@ -219,25 +208,18 @@ protected String getBinding(/*Library library,*/ NarArtifact dependency) ILibrary.STATIC); return binding; } - - public File getArtifactDirectory(NarArtifact dependency, File unpackDirectory ) - { + + public File getArtifactDirectory(NarArtifact dependency, File unpackDirectory) { File targetDirectory = dependency.getNarInfo().getTargetDirectory(); - if ( targetDirectory != null ) { + if (targetDirectory != null) { return targetDirectory; - } - else - { + } else { return unpackDirectory; } } - private List getAttachedNarArtifacts( - NarArtifact dependency, AOL aol, String type) - throws MojoExecutionException, MojoFailureException { - getLog().debug( - "GetNarDependencies for " + dependency + ", aol: " + aol - + ", type: " + type); + private List getAttachedNarArtifacts(NarArtifact dependency, AOL aol, String type) throws MojoExecutionException, MojoFailureException { + getLog().debug("GetNarDependencies for " + dependency + ", aol: " + aol + ", type: " + type); List artifactList = new ArrayList(); NarInfo narInfo = dependency.getNarInfo(); String[] nars = narInfo.getAttachedNars(aol, type); @@ -258,24 +240,16 @@ private List getAttachedNarArtifacts( // translate for instance g++ to gcc... AOL aolString = narInfo.getAOL(aol); if (aolString != null) { - classifier = NarUtil.replace("${aol}", - aolString.toString(), classifier); + classifier = NarUtil.replace("${aol}", aolString.toString(), classifier); } - String version = nar.length >= 5 ? nar[4].trim() - : dependency.getVersion(); - artifactList.add(new AttachedNarArtifact(groupId, - artifactId, version, dependency.getScope(), - ext, classifier, dependency.isOptional(), + String version = nar.length >= 5 ? nar[4].trim() : dependency.getVersion(); + artifactList.add(new AttachedNarArtifact(groupId, artifactId, version, dependency.getScope(), ext, classifier, dependency.isOptional(), dependency.getFile())); } catch (InvalidVersionSpecificationException e) { - throw new MojoExecutionException( - "Error while reading nar file for dependency " - + dependency, e); + throw new MojoExecutionException("Error while reading nar file for dependency " + dependency, e); } } else { - getLog().warn( - "nars property in " + dependency.getArtifactId() - + " contains invalid field: '" + nars[j] + getLog().warn("nars property in " + dependency.getArtifactId() + " contains invalid field: '" + nars[j] // + "' for type: " + type ); } @@ -285,10 +259,8 @@ private List getAttachedNarArtifacts( } @SuppressWarnings("deprecation") - public final void downloadAttachedNars( - List dependencies) - throws MojoExecutionException, MojoFailureException { - getLog().debug( "Download for NarDependencies {" ); + public final void downloadAttachedNars(List dependencies) throws MojoExecutionException, MojoFailureException { + getLog().debug("Download for NarDependencies {"); for (Iterator i = dependencies.iterator(); i.hasNext();) { getLog().debug(" - " + (i.next())); } @@ -309,8 +281,8 @@ public final void downloadAttachedNars( } } - public void prepareNarArtifacts(final ConfiguratorContext context, - IMavenProjectFacade facade, IProgressMonitor monitor) throws MojoExecutionException, CoreException, MojoFailureException { + public void prepareNarArtifacts(final ConfiguratorContext context, IMavenProjectFacade facade, IProgressMonitor monitor) throws MojoExecutionException, + CoreException, MojoFailureException { narDependencies = new LinkedList(); for (Iterator i = getArtifacts().iterator(); i.hasNext();) { Artifact dependency = i.next(); @@ -322,8 +294,7 @@ public void prepareNarArtifacts(final ConfiguratorContext context, if (eclipseLayout != null) { layout = eclipseLayout; narInfo = getNarInfo(dependency, eclipseLayout); - } - else { + } else { layout = getLayout(); narInfo = getNarInfo(dependency); } @@ -332,31 +303,26 @@ public void prepareNarArtifacts(final ConfiguratorContext context, narDependencies.add(new NarArtifact(dependency, narInfo, layout)); } } - getLog().debug( - "Dependencies contained " + narDependencies.size() - + " NAR artifacts."); + getLog().debug("Dependencies contained " + narDependencies.size() + " NAR artifacts."); } - private EclipseNarLayout resolveEclipseProject(final Artifact artifact, final ConfiguratorContext context, - IMavenProjectFacade facade, IProgressMonitor monitor) throws CoreException { + private EclipseNarLayout resolveEclipseProject(final Artifact artifact, final ConfiguratorContext context, IMavenProjectFacade facade, + IProgressMonitor monitor) throws CoreException { final IMavenProjectRegistry projectManager = context.getProjectManager(); if (!Artifact.SCOPE_COMPILE.equals(artifact.getScope()) && !Artifact.SCOPE_TEST.equals(artifact.getScope())) { return null; } - IMavenProjectFacade dependency = projectManager.getMavenProject( - artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion()); + IMavenProjectFacade dependency = projectManager.getMavenProject(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion()); if (dependency == null) { return null; } if (dependency.getProject().equals(facade.getProject())) { return null; } - getLog().debug("Found dependency project " - + dependency.getProject().getName()); + getLog().debug("Found dependency project " + dependency.getProject().getName()); EclipseNarLayout layout = new EclipseNarLayout(getLog()); layout.setProject(dependency); - List narExecutions = MavenUtils.buildCompileNarExecutions(context, - dependency, monitor); + List narExecutions = MavenUtils.buildCompileNarExecutions(context, dependency, monitor); getLog().debug("Found " + narExecutions.size() + " compile executions"); com.github.sdedwards.m2e_nar.internal.model.NarBuildArtifact artifactSettings = null; for (NarExecution narSettings : narExecutions) { @@ -375,5 +341,5 @@ private EclipseNarLayout resolveEclipseProject(final Artifact artifact, final Co return layout; } return null; - } + } } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/AbstractNarLayout.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/AbstractNarLayout.java index 5d11753..f50ac2d 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/AbstractNarLayout.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/AbstractNarLayout.java @@ -29,66 +29,44 @@ * @author Mark Donszelmann (Mark.Donszelmann@gmail.com) * @version $Id$ */ -public abstract class AbstractNarLayout - implements NarLayout, NarConstants -{ - private Log log; +public abstract class AbstractNarLayout implements NarLayout, NarConstants { + private Log log; - protected AbstractNarLayout( Log log ) - { - this.log = log; - } + protected AbstractNarLayout(Log log) { + this.log = log; + } - protected Log getLog() - { - return log; - } + protected Log getLog() { + return log; + } - /** - * @return - * @throws MojoExecutionException - */ - public static NarLayout getLayout( String layoutName, Log log ) - throws MojoExecutionException - { - String className = - layoutName.indexOf( '.' ) < 0 ? NarLayout21.class.getPackage().getName() + "." + layoutName : layoutName; - log.debug( "Using " + className ); - Class cls; - try - { - cls = Class.forName( className ); - Constructor ctor = cls.getConstructor( new Class[] { Log.class } ); - return (NarLayout) ctor.newInstance( new Object[] { log } ); - } - catch ( ClassNotFoundException e ) - { - throw new MojoExecutionException( "Cannot find class for layout " + className, e ); - } - catch ( InstantiationException e ) - { - throw new MojoExecutionException( "Cannot instantiate class for layout " + className, e ); - } - catch ( IllegalAccessException e ) - { - throw new MojoExecutionException( "Cannot access class for layout " + className, e ); - } - catch ( SecurityException e ) - { - throw new MojoExecutionException( "Cannot access class for layout " + className, e ); - } - catch ( NoSuchMethodException e ) - { - throw new MojoExecutionException( "Cannot find ctor(Log) for layout " + className, e ); - } - catch ( IllegalArgumentException e ) - { - throw new MojoExecutionException( "Wrong arguments ctor(Log) for layout " + className, e ); - } - catch ( InvocationTargetException e ) - { - throw new MojoExecutionException( "Cannot invokector(Log) for layout " + className, e ); - } - } + /** + * @return + * @throws MojoExecutionException + */ + public static NarLayout getLayout(String layoutName, Log log) throws MojoExecutionException { + String className = layoutName.indexOf('.') < 0 ? NarLayout21.class.getPackage().getName() + "." + layoutName : layoutName; + log.debug("Using " + className); + Class cls; + try { + cls = Class.forName(className); + Constructor ctor = cls.getConstructor(new Class[] { Log.class }); + return (NarLayout) ctor.newInstance(new Object[] { log }); + } catch (ClassNotFoundException e) { + throw new MojoExecutionException("Cannot find class for layout " + className, e); + } catch (InstantiationException e) { + throw new MojoExecutionException("Cannot instantiate class for layout " + className, e); + } catch (IllegalAccessException e) { + throw new MojoExecutionException("Cannot access class for layout " + className, e); + } catch (SecurityException e) { + throw new MojoExecutionException("Cannot access class for layout " + className, e); + } catch (NoSuchMethodException e) { + throw new MojoExecutionException("Cannot find ctor(Log) for layout " + className, e); + } catch (IllegalArgumentException e) { + throw new MojoExecutionException("Wrong arguments ctor(Log) for layout " + className, e); + } catch (InvocationTargetException e) { + throw new MojoExecutionException("Cannot invokector(Log) for layout " + className, e); + } + } } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/AbstractNarMojo.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/AbstractNarMojo.java index 8a33dd9..0af82e0 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/AbstractNarMojo.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/AbstractNarMojo.java @@ -100,9 +100,9 @@ public abstract class AbstractNarMojo private File outputDirectory; /** - * @parameter property="project.build.outputDirectory" - * @readonly - */ + * @parameter property="project.build.outputDirectory" + * @readonly + */ protected File classesDirectory; /** diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/AttachedNarArtifact.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/AttachedNarArtifact.java index 1350f54..c092e7b 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/AttachedNarArtifact.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/AttachedNarArtifact.java @@ -32,70 +32,53 @@ * * @author Mark Donszelmann */ -public class AttachedNarArtifact - extends DefaultArtifact -{ - public AttachedNarArtifact( String groupId, String artifactId, String version, String scope, String type, - String classifier, boolean optional, File file ) - throws InvalidVersionSpecificationException - { - super( groupId, artifactId, VersionRange.createFromVersionSpec( version ), scope, type, classifier, null, - optional ); - setArtifactHandler( new Handler( classifier ) ); - setFile(new File(file.getParentFile(), artifactId+"-"+VersionRange.createFromVersionSpec( version )+"-"+classifier+"."+type)); - } +public class AttachedNarArtifact extends DefaultArtifact { + public AttachedNarArtifact(String groupId, String artifactId, String version, String scope, String type, String classifier, boolean optional, File file) + throws InvalidVersionSpecificationException { + super(groupId, artifactId, VersionRange.createFromVersionSpec(version), scope, type, classifier, null, optional); + setArtifactHandler(new Handler(classifier)); + setFile(new File(file.getParentFile(), artifactId + "-" + VersionRange.createFromVersionSpec(version) + "-" + classifier + "." + type)); + } - // NOTE: not used - public AttachedNarArtifact( Artifact parent, String type, String classifier ) - { - super( parent.getGroupId(), parent.getArtifactId(), parent.getVersionRange(), parent.getScope(), type, - classifier, null, parent.isOptional() ); - setArtifactHandler( new Handler( classifier ) ); - } + // NOTE: not used + public AttachedNarArtifact(Artifact parent, String type, String classifier) { + super(parent.getGroupId(), parent.getArtifactId(), parent.getVersionRange(), parent.getScope(), type, classifier, null, parent.isOptional()); + setArtifactHandler(new Handler(classifier)); + } - private class Handler - implements ArtifactHandler - { - private String classifier; + private class Handler implements ArtifactHandler { + private String classifier; - Handler( String classifier ) - { - this.classifier = classifier; - } + Handler(String classifier) { + this.classifier = classifier; + } - public String getExtension() - { - return "nar"; - } + public String getExtension() { + return "nar"; + } - public String getDirectory() - { - return "nars"; - } + public String getDirectory() { + return "nars"; + } - public String getClassifier() - { - return classifier; - } + public String getClassifier() { + return classifier; + } - public String getPackaging() - { - return "nar"; - } + public String getPackaging() { + return "nar"; + } - public boolean isIncludesDependencies() - { - return false; - } + public boolean isIncludesDependencies() { + return false; + } - public String getLanguage() - { - return "native"; - } + public String getLanguage() { + return "native"; + } - public boolean isAddedToClasspath() - { - return true; - } - } + public boolean isAddedToClasspath() { + return true; + } + } } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/C.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/C.java index 8e09d99..a0f2a90 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/C.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/C.java @@ -24,16 +24,12 @@ * * @author Mark Donszelmann */ -public class C - extends Compiler -{ +public class C extends Compiler { - public C() - { - } + public C() { + } - public final String getLanguage() - { - return "c"; - } + public final String getLanguage() { + return "c"; + } } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Compiler.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Compiler.java index c0ead4a..d81fb7d 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Compiler.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Compiler.java @@ -41,580 +41,546 @@ * * @author Mark Donszelmann */ -public abstract class Compiler implements ICompiler -{ - - /** - * The name of the compiler. Some choices are: "msvc", "g++", "gcc", "CC", "cc", "icc", "icpc", ... Default is - * Architecture-OS-Linker specific: FIXME: table missing - * - * @parameter default-value="" - */ - private String name; - - /** - * Path location of the compile tool - * - * @parameter default-value="" - */ - private String toolPath; - - /** - * Source directory for native files - * - * @parameter default-value="${basedir}/src/main" - * @required - */ - private File sourceDirectory; - - /** - * Source directory for native test files - * - * @parameter default-value="${basedir}/src/test" - * @required - */ - private File testSourceDirectory; - - /** - * Include patterns for sources - * - * @parameter default-value="" - * @required - */ - private Set includes = new HashSet(); - - /** - * Exclude patterns for sources - * - * @parameter default-value="" - * @required - */ - private Set excludes = new HashSet(); - - /** - * Include patterns for test sources - * - * @parameter default-value="" - * @required - */ - private Set testIncludes = new HashSet(); - - /** - * Exclude patterns for test sources - * - * @parameter default-value="" - * @required - */ - private Set testExcludes = new HashSet(); - - /** - * Compile with debug information. - * - * @parameter default-value="false" - * @required - */ - // Done - private boolean debug = false; - - /** - * Enables generation of exception handling code. - * - * @parameter default-value="true" - * @required - */ - // Done - private boolean exceptions = true; - - /** - * Enables run-time type information. - * - * @parameter default-value="true" - * @required - */ - // Done - private boolean rtti = true; - - /** - * Sets optimization. Possible choices are: "none", "size", "minimal", "speed", "full", "aggressive", "extreme", - * "unsafe". - * - * @parameter default-value="none" - * @required - */ - // Done - private String optimize = "none"; - - /** - * Enables or disables generation of multi-threaded code. Default value: false, except on Windows. - * - * @parameter default-value="false" - * @required - */ - // not used - private boolean multiThreaded = false; - - /** - * Defines - * - * @parameter default-value="" - */ - private List defines; - - /** - * Defines for the compiler as a comma separated list of name[=value] pairs, where the value is optional. Will work - * in combination with <defines>. - * - * @parameter default-value="" - */ - private String defineSet; - - /** - * Clears default defines - * - * @parameter default-value="false" - * @required - */ - private boolean clearDefaultDefines; - - /** - * Undefines - * - * @parameter default-value="" - */ - private List undefines; - - /** - * Undefines for the compiler as a comma separated list of name[=value] pairs where the value is optional. Will work - * in combination with <undefines>. - * - * @parameter default-value="" - */ - private String undefineSet; - - /** - * Clears default undefines - * - * @parameter default-value="false" - * @required - */ - private boolean clearDefaultUndefines; - - /** - * Include Paths. Defaults to "${sourceDirectory}/include" - * - * @parameter default-value="" - */ - private List includePaths; - - /** - * Test Include Paths. Defaults to "${testSourceDirectory}/include" - * - * @parameter default-value="" - */ - private List testIncludePaths; - - /** - * System Include Paths, which are added at the end of all include paths - * - * @parameter default-value="" - */ - private List systemIncludePaths; - - /** - * Additional options for the C++ compiler Defaults to Architecture-OS-Linker specific values. FIXME table missing - * - * @parameter default-value="" - */ - private List options; - - /** - * Options for the compiler as a whitespace separated list. Will work in combination with <options>. - * - * @parameter default-value="" - */ - private String optionSet; - - /** - * Clears default options - * - * @parameter default-value="false" - * @required - */ - private boolean clearDefaultOptions; - - /** - * Comma separated list of filenames to compile in order - * - * @parameter default-value="" - */ - private String compileOrder; - - private AbstractCompileMojo mojo; - - public static final String MAIN = "main"; - public static final String TEST = "test"; - - protected Compiler() - { - } - - /* (non-Javadoc) +public abstract class Compiler implements ICompiler { + + /** + * The name of the compiler. Some choices are: "msvc", "g++", "gcc", "CC", + * "cc", "icc", "icpc", ... Default is Architecture-OS-Linker specific: + * FIXME: table missing + * + * @parameter default-value="" + */ + private String name; + + /** + * Path location of the compile tool + * + * @parameter default-value="" + */ + private String toolPath; + + /** + * Source directory for native files + * + * @parameter default-value="${basedir}/src/main" + * @required + */ + private File sourceDirectory; + + /** + * Source directory for native test files + * + * @parameter default-value="${basedir}/src/test" + * @required + */ + private File testSourceDirectory; + + /** + * Include patterns for sources + * + * @parameter default-value="" + * @required + */ + private Set includes = new HashSet(); + + /** + * Exclude patterns for sources + * + * @parameter default-value="" + * @required + */ + private Set excludes = new HashSet(); + + /** + * Include patterns for test sources + * + * @parameter default-value="" + * @required + */ + private Set testIncludes = new HashSet(); + + /** + * Exclude patterns for test sources + * + * @parameter default-value="" + * @required + */ + private Set testExcludes = new HashSet(); + + /** + * Compile with debug information. + * + * @parameter default-value="false" + * @required + */ + // Done + private boolean debug = false; + + /** + * Enables generation of exception handling code. + * + * @parameter default-value="true" + * @required + */ + // Done + private boolean exceptions = true; + + /** + * Enables run-time type information. + * + * @parameter default-value="true" + * @required + */ + // Done + private boolean rtti = true; + + /** + * Sets optimization. Possible choices are: "none", "size", "minimal", + * "speed", "full", "aggressive", "extreme", "unsafe". + * + * @parameter default-value="none" + * @required + */ + // Done + private String optimize = "none"; + + /** + * Enables or disables generation of multi-threaded code. Default value: + * false, except on Windows. + * + * @parameter default-value="false" + * @required + */ + // not used + private boolean multiThreaded = false; + + /** + * Defines + * + * @parameter default-value="" + */ + private List defines; + + /** + * Defines for the compiler as a comma separated list of name[=value] pairs, + * where the value is optional. Will work in combination with + * <defines>. + * + * @parameter default-value="" + */ + private String defineSet; + + /** + * Clears default defines + * + * @parameter default-value="false" + * @required + */ + private boolean clearDefaultDefines; + + /** + * Undefines + * + * @parameter default-value="" + */ + private List undefines; + + /** + * Undefines for the compiler as a comma separated list of name[=value] + * pairs where the value is optional. Will work in combination with + * <undefines>. + * + * @parameter default-value="" + */ + private String undefineSet; + + /** + * Clears default undefines + * + * @parameter default-value="false" + * @required + */ + private boolean clearDefaultUndefines; + + /** + * Include Paths. Defaults to "${sourceDirectory}/include" + * + * @parameter default-value="" + */ + private List includePaths; + + /** + * Test Include Paths. Defaults to "${testSourceDirectory}/include" + * + * @parameter default-value="" + */ + private List testIncludePaths; + + /** + * System Include Paths, which are added at the end of all include paths + * + * @parameter default-value="" + */ + private List systemIncludePaths; + + /** + * Additional options for the C++ compiler Defaults to + * Architecture-OS-Linker specific values. FIXME table missing + * + * @parameter default-value="" + */ + private List options; + + /** + * Options for the compiler as a whitespace separated list. Will work in + * combination with <options>. + * + * @parameter default-value="" + */ + private String optionSet; + + /** + * Clears default options + * + * @parameter default-value="false" + * @required + */ + private boolean clearDefaultOptions; + + /** + * Comma separated list of filenames to compile in order + * + * @parameter default-value="" + */ + private String compileOrder; + + private AbstractCompileMojo mojo; + + public static final String MAIN = "main"; + public static final String TEST = "test"; + + protected Compiler() { + } + + /* + * (non-Javadoc) + * * @see com.github.maven_nar.ICompiler#getName() */ - public String getName() - throws MojoFailureException, MojoExecutionException - { - // adjust default values - if ( name == null ) - { - name = mojo.getNarProperties().getProperty( getPrefix() + "compiler" ); - } - return name; - } - - public final void setAbstractCompileMojo( AbstractCompileMojo mojo ) - { - this.mojo = mojo; - } - - public final List/* */getSourceDirectories() - { - return getSourceDirectories( "dummy" ); - } - - /* (non-Javadoc) - * @see com.github.maven_nar.ICompiler#getSourceDirectories(java.lang.String) - */ - public List getSourceDirectories( String type ) - { - List sourceDirectories = new ArrayList(); - File baseDir = mojo.getMavenProject().getBasedir(); - - if ( type.equals( TEST ) ) - { - if ( testSourceDirectory == null ) - { - testSourceDirectory = new File( baseDir, "/src/test" ); - } - if ( testSourceDirectory.exists() ) - { - sourceDirectories.add( testSourceDirectory ); - } - - for ( Iterator i = mojo.getMavenProject().getTestCompileSourceRoots().iterator(); i.hasNext(); ) - { - File extraTestSourceDirectory = new File( (String) i.next() ); - if ( extraTestSourceDirectory.exists() ) - { - sourceDirectories.add( extraTestSourceDirectory ); - } - } - } - else - { - if ( sourceDirectory == null ) - { - sourceDirectory = new File( baseDir, "src/main" ); - } - if ( sourceDirectory.exists() ) - { - sourceDirectories.add( sourceDirectory ); - } - - for ( Iterator i = mojo.getMavenProject().getCompileSourceRoots().iterator(); i.hasNext(); ) - { - File extraSourceDirectory = new File( (String) i.next() ); - if ( extraSourceDirectory.exists() ) - { - sourceDirectories.add( extraSourceDirectory ); - } - } - } - - if ( mojo.getLog().isDebugEnabled() ) - { - for ( Iterator i = sourceDirectories.iterator(); i.hasNext(); ) - { - mojo.getLog().debug( "Added to sourceDirectory: " + ( (File) i.next() ).getPath() ); - } - } - return sourceDirectories; - } - - /* (non-Javadoc) + public String getName() throws MojoFailureException, MojoExecutionException { + // adjust default values + if (name == null) { + name = mojo.getNarProperties().getProperty(getPrefix() + "compiler"); + } + return name; + } + + public final void setAbstractCompileMojo(AbstractCompileMojo mojo) { + this.mojo = mojo; + } + + public final List/* */getSourceDirectories() { + return getSourceDirectories("dummy"); + } + + /* + * (non-Javadoc) + * + * @see + * com.github.maven_nar.ICompiler#getSourceDirectories(java.lang.String) + */ + public List getSourceDirectories(String type) { + List sourceDirectories = new ArrayList(); + File baseDir = mojo.getMavenProject().getBasedir(); + + if (type.equals(TEST)) { + if (testSourceDirectory == null) { + testSourceDirectory = new File(baseDir, "/src/test"); + } + if (testSourceDirectory.exists()) { + sourceDirectories.add(testSourceDirectory); + } + + for (Iterator i = mojo.getMavenProject().getTestCompileSourceRoots().iterator(); i.hasNext();) { + File extraTestSourceDirectory = new File((String) i.next()); + if (extraTestSourceDirectory.exists()) { + sourceDirectories.add(extraTestSourceDirectory); + } + } + } else { + if (sourceDirectory == null) { + sourceDirectory = new File(baseDir, "src/main"); + } + if (sourceDirectory.exists()) { + sourceDirectories.add(sourceDirectory); + } + + for (Iterator i = mojo.getMavenProject().getCompileSourceRoots().iterator(); i.hasNext();) { + File extraSourceDirectory = new File((String) i.next()); + if (extraSourceDirectory.exists()) { + sourceDirectories.add(extraSourceDirectory); + } + } + } + + if (mojo.getLog().isDebugEnabled()) { + for (Iterator i = sourceDirectories.iterator(); i.hasNext();) { + mojo.getLog().debug("Added to sourceDirectory: " + ((File) i.next()).getPath()); + } + } + return sourceDirectories; + } + + /* + * (non-Javadoc) + * * @see com.github.maven_nar.ICompiler#getIncludePaths(java.lang.String) */ - public final List getIncludePaths( String type ) - { - List includePathList = createIncludePaths(type, type.equals( TEST ) ? testIncludePaths : includePaths); - if (type.equals(TEST)) { - // Add main includes paths too - includePathList.addAll(createIncludePaths(MAIN, includePaths)); - } - return includePathList; - } - - private List createIncludePaths( String type, List paths ) - { - List includeList = paths; - if ( includeList == null || ( paths.size() == 0 ) ) - { - includeList = new ArrayList(); - for ( Iterator i = getSourceDirectories( type ).iterator(); i.hasNext(); ) - { - //VR 20100318 only add include directories that exist - we now fail the build fast if an include directory does not exist - File includePath = new File( (File) i.next(), "include" ); - if(includePath.isDirectory()) { - includeList.add( includePath.getPath() ); - } - } - } - return includeList; - } - - /* (non-Javadoc) + public final List getIncludePaths(String type) { + List includePathList = createIncludePaths(type, type.equals(TEST) ? testIncludePaths : includePaths); + if (type.equals(TEST)) { + // Add main includes paths too + includePathList.addAll(createIncludePaths(MAIN, includePaths)); + } + return includePathList; + } + + private List createIncludePaths(String type, List paths) { + List includeList = paths; + if (includeList == null || (paths.size() == 0)) { + includeList = new ArrayList(); + for (Iterator i = getSourceDirectories(type).iterator(); i.hasNext();) { + // VR 20100318 only add include directories that exist - we now + // fail the build fast if an include directory does not exist + File includePath = new File((File) i.next(), "include"); + if (includePath.isDirectory()) { + includeList.add(includePath.getPath()); + } + } + } + return includeList; + } + + /* + * (non-Javadoc) + * * @see com.github.maven_nar.ICompiler#getSystemIncludePaths() */ - public final List/* */getSystemIncludePaths( ) - { - return systemIncludePaths; - } + public final List/* */getSystemIncludePaths() { + return systemIncludePaths; + } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see com.github.maven_nar.ICompiler#getIncludes() */ - public final Set getIncludes() - throws MojoFailureException, MojoExecutionException - { - return getIncludes( "main" ); - } - - public final Set getIncludes( String type ) - throws MojoFailureException, MojoExecutionException - { - Set result = new HashSet(); - if ( !type.equals( TEST ) && !includes.isEmpty() ) - { - result.addAll( includes ); - } - else if ( type.equals( TEST ) && !testIncludes.isEmpty() ) - { - result.addAll( testIncludes ); - } - else - { - String defaultIncludes = mojo.getNarProperties().getProperty( getPrefix() + "includes" ); - if ( defaultIncludes != null ) - { - String[] include = defaultIncludes.split( " " ); - for ( int i = 0; i < include.length; i++ ) - { - result.add( include[i].trim() ); - } - } - } - return result; - } - - /* (non-Javadoc) + public final Set getIncludes() throws MojoFailureException, MojoExecutionException { + return getIncludes("main"); + } + + public final Set getIncludes(String type) throws MojoFailureException, MojoExecutionException { + Set result = new HashSet(); + if (!type.equals(TEST) && !includes.isEmpty()) { + result.addAll(includes); + } else if (type.equals(TEST) && !testIncludes.isEmpty()) { + result.addAll(testIncludes); + } else { + String defaultIncludes = mojo.getNarProperties().getProperty(getPrefix() + "includes"); + if (defaultIncludes != null) { + String[] include = defaultIncludes.split(" "); + for (int i = 0; i < include.length; i++) { + result.add(include[i].trim()); + } + } + } + return result; + } + + /* + * (non-Javadoc) + * * @see com.github.maven_nar.ICompiler#getExcludes() */ - public final Set getExcludes() - throws MojoFailureException, MojoExecutionException - { - return getExcludes( "main", null ); - } - - public final Set getExcludes( String type, ITest currentTest ) - throws MojoFailureException, MojoExecutionException - { - Set result = new HashSet(); - if ( type.equals( TEST ) && !testExcludes.isEmpty() ) - { - result.addAll( testExcludes ); - } - else if ( !excludes.isEmpty() ) - { - result.addAll( excludes ); - } - else - { - String defaultExcludes = mojo.getNarProperties().getProperty( getPrefix() + "excludes" ); - if ( defaultExcludes != null ) - { - String[] exclude = defaultExcludes.split( " " ); - for ( int i = 0; i < exclude.length; i++ ) - { - result.add( exclude[i].trim() ); - } - } - } - // now add all but the current test to the excludes - String testName = null; - if (currentTest != null) { - testName = currentTest.getName(); - } - for ( Iterator i = mojo.getTests().iterator(); i.hasNext(); ) - { - Test test = (Test) i.next(); - if ( !test.getName().equals( testName ) ) - { - result.add( "**/" + test.getName() + ".*" ); - } - } - - return result; - } - - protected final String getPrefix() - throws MojoFailureException, MojoExecutionException - { - return mojo.getAOL().getKey() + "." + getLanguage() + "."; - } - - /* (non-Javadoc) + public final Set getExcludes() throws MojoFailureException, MojoExecutionException { + return getExcludes("main", null); + } + + public final Set getExcludes(String type, ITest currentTest) throws MojoFailureException, MojoExecutionException { + Set result = new HashSet(); + if (type.equals(TEST) && !testExcludes.isEmpty()) { + result.addAll(testExcludes); + } else if (!excludes.isEmpty()) { + result.addAll(excludes); + } else { + String defaultExcludes = mojo.getNarProperties().getProperty(getPrefix() + "excludes"); + if (defaultExcludes != null) { + String[] exclude = defaultExcludes.split(" "); + for (int i = 0; i < exclude.length; i++) { + result.add(exclude[i].trim()); + } + } + } + // now add all but the current test to the excludes + String testName = null; + if (currentTest != null) { + testName = currentTest.getName(); + } + for (Iterator i = mojo.getTests().iterator(); i.hasNext();) { + Test test = (Test) i.next(); + if (!test.getName().equals(testName)) { + result.add("**/" + test.getName() + ".*"); + } + } + + return result; + } + + protected final String getPrefix() throws MojoFailureException, MojoExecutionException { + return mojo.getAOL().getKey() + "." + getLanguage() + "."; + } + + /* + * (non-Javadoc) + * * @see com.github.maven_nar.ICompiler#isDebug() */ - public boolean isDebug() { + public boolean isDebug() { return debug; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see com.github.maven_nar.ICompiler#isRtti() */ public boolean isRtti() { return rtti; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see com.github.maven_nar.ICompiler#getOptimize() */ public String getOptimize() { return optimize; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see com.github.maven_nar.ICompiler#isMultiThreaded() */ public boolean isMultiThreaded() { - return mojo.getOS().equals( "Windows" ) ? true : multiThreaded; + return mojo.getOS().equals("Windows") ? true : multiThreaded; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see com.github.maven_nar.ICompiler#getDefines() */ public List getDefines() throws MojoFailureException, MojoExecutionException { List defineList = new ArrayList(); - if ( defines != null ) - { - defineList.addAll( defines ); - } - - if ( defineSet != null ) - { - - String[] defList = defineSet.split( "," ); - - for ( int i = 0; i < defList.length; i++ ) - { - defineList.add( defList[i].trim() ); - } - } - - if ( !clearDefaultDefines ) - { - String defaultDefines = mojo.getNarProperties().getProperty( getPrefix() + "defines" ); - if ( defaultDefines != null ) - { - String[] define = new NarUtil.StringArrayBuilder( defaultDefines ).getValue(); - for ( int i = 0; i < define.length; i++ ) - { - defineList.add( define[i] ); - } - } - } - return defineList; + if (defines != null) { + defineList.addAll(defines); + } + + if (defineSet != null) { + + String[] defList = defineSet.split(","); + + for (int i = 0; i < defList.length; i++) { + defineList.add(defList[i].trim()); + } + } + + if (!clearDefaultDefines) { + String defaultDefines = mojo.getNarProperties().getProperty(getPrefix() + "defines"); + if (defaultDefines != null) { + String[] define = new NarUtil.StringArrayBuilder(defaultDefines).getValue(); + for (int i = 0; i < define.length; i++) { + defineList.add(define[i]); + } + } + } + return defineList; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see com.github.maven_nar.ICompiler#getUndefines() */ public List getUndefines() throws MojoFailureException, MojoExecutionException { List undefineList = new ArrayList(); - if ( undefines != null ) - { - undefineList.addAll(undefines); - } - - if ( undefineSet != null ) - { - - String[] undefList = undefineSet.split( "," ); - - for ( int i = 0; i < undefList.length; i++ ) - { - undefineList.add( undefList[i].trim() ); - } - } - - if ( !clearDefaultUndefines ) - { - String defaultUndefines = mojo.getNarProperties().getProperty( getPrefix() + "undefines" ); - if ( defaultUndefines != null ) - { - String[] undefine = new NarUtil.StringArrayBuilder( defaultUndefines ).getValue(); - for ( int i = 0; i < undefine.length; i++ ) - { - undefineList.add( undefine[i] ); - } - } - } - return undefineList; + if (undefines != null) { + undefineList.addAll(undefines); + } + + if (undefineSet != null) { + + String[] undefList = undefineSet.split(","); + + for (int i = 0; i < undefList.length; i++) { + undefineList.add(undefList[i].trim()); + } + } + + if (!clearDefaultUndefines) { + String defaultUndefines = mojo.getNarProperties().getProperty(getPrefix() + "undefines"); + if (defaultUndefines != null) { + String[] undefine = new NarUtil.StringArrayBuilder(defaultUndefines).getValue(); + for (int i = 0; i < undefine.length; i++) { + undefineList.add(undefine[i]); + } + } + } + return undefineList; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see com.github.maven_nar.ICompiler#getOptions() */ public List getOptions() throws MojoFailureException, MojoExecutionException { List optionList = new ArrayList(); - if ( options != null ) - { - optionList.addAll(options); - } - - if ( optionSet != null ) - { - - String[] opts = optionSet.split( "\\s" ); - - for ( int i = 0; i < opts.length; i++ ) - { - optionList.add( opts[i] ); - } - } - - if ( !clearDefaultOptions ) - { - String optionsProperty = mojo.getNarProperties().getProperty( getPrefix() + "options" ); - if ( optionsProperty != null ) - { - String[] option = optionsProperty.split( " " ); - for ( int i = 0; i < option.length; i++ ) - { - optionList.add( option[i] ); - } - } - } - return optionList; + if (options != null) { + optionList.addAll(options); + } + + if (optionSet != null) { + + String[] opts = optionSet.split("\\s"); + + for (int i = 0; i < opts.length; i++) { + optionList.add(opts[i]); + } + } + + if (!clearDefaultOptions) { + String optionsProperty = mojo.getNarProperties().getProperty(getPrefix() + "options"); + if (optionsProperty != null) { + String[] option = optionsProperty.split(" "); + for (int i = 0; i < option.length; i++) { + optionList.add(option[i]); + } + } + } + return optionList; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see com.github.maven_nar.ICompiler#isExceptions() */ public boolean isExceptions() { return exceptions; } - protected abstract String getLanguage(); + protected abstract String getLanguage(); } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Cpp.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Cpp.java index 3ff8b22..7955f2a 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Cpp.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Cpp.java @@ -24,15 +24,11 @@ * * @author Mark Donszelmann */ -public class Cpp - extends Compiler -{ - public Cpp() - { - } +public class Cpp extends Compiler { + public Cpp() { + } - public final String getLanguage() - { - return "cpp"; - } + public final String getLanguage() { + return "cpp"; + } } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/EclipseNarLayout.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/EclipseNarLayout.java index d443e98..8a7dcd8 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/EclipseNarLayout.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/EclipseNarLayout.java @@ -51,8 +51,7 @@ public IMavenProjectFacade getProject() { public void addIncludeDirectory(File includeDirectory) { if (!includeDirectory.isAbsolute()) { - includeDirectory = new File(project.getProject().getLocation() - .toFile(), includeDirectory.getPath()); + includeDirectory = new File(project.getProject().getLocation().toFile(), includeDirectory.getPath()); } this.includeDirectories.add(includeDirectory); } @@ -65,74 +64,67 @@ public File getNoArchDirectory(File baseDir, NarArtifact artifact) { return null; } - public File getNoArchDirectory( File baseDir, MavenProject project ) - { - return null; - } + public File getNoArchDirectory(File baseDir, MavenProject project) { + return null; + } - private File getTargetDirectory(String type) { + private File getTargetDirectory(String type) { return new File(project.getProject().getLocation().toFile(), CdtUtils.DEFAULT_CONFIG_NAME_PREFIX + type); } - public final List getIncludeDirectories(File baseDir, - NarArtifact artifact) { + public final List getIncludeDirectories(File baseDir, NarArtifact artifact) { return includeDirectories; } - /* - * (non-Javadoc) - * @see com.github.maven_nar.NarLayout#getIncludeDirectory(java.io.File) - */ - public final File getIncludeDirectory( File baseDir, MavenProject project ) - { - return null; - } + /* + * (non-Javadoc) + * + * @see com.github.maven_nar.NarLayout#getIncludeDirectory(java.io.File) + */ + public final File getIncludeDirectory(File baseDir, MavenProject project) { + return null; + } - public final File getLibDirectory(File baseDir, NarArtifact artifact, String aol, String type) - throws MojoExecutionException { + public final File getLibDirectory(File baseDir, NarArtifact artifact, String aol, String type) throws MojoExecutionException { + return getTargetDirectory(type); + } + + /* + * (non-Javadoc) + * + * @see com.github.maven_nar.NarLayout#getLibDir(java.io.File, + * com.github.maven_nar.AOL, java.lang.String) + */ + public final File getLibDirectory(File baseDir, MavenProject project, String aol, String type) throws MojoExecutionException { return getTargetDirectory(type); } - /* - * (non-Javadoc) - * @see com.github.maven_nar.NarLayout#getLibDir(java.io.File, com.github.maven_nar.AOL, - * java.lang.String) - */ - public final File getLibDirectory( File baseDir, MavenProject project, String aol, String type ) - throws MojoExecutionException - { - return getTargetDirectory(type); - } - public final File getBinDirectory(File baseDir, NarArtifact artifact, String aol) { return getTargetDirectory(ILibrary.EXECUTABLE); } - /* - * (non-Javadoc) - * @see com.github.maven_nar.NarLayout#getLibDir(java.io.File, com.github.maven_nar.AOL, - * java.lang.String) - */ - public final File getBinDirectory( File baseDir, MavenProject project, String aol ) - { - return getTargetDirectory(ILibrary.EXECUTABLE); - } - - /* - public final void prepareNarInfo(File baseDir, MavenProject project, - NarInfo narInfo, AbstractNarMojo mojo) - throws MojoExecutionException { + /* + * (non-Javadoc) + * + * @see com.github.maven_nar.NarLayout#getLibDir(java.io.File, + * com.github.maven_nar.AOL, java.lang.String) + */ + public final File getBinDirectory(File baseDir, MavenProject project, String aol) { + return getTargetDirectory(ILibrary.EXECUTABLE); } - public File getNarUnpackDirectory(File baseUnpackDirectory, File narFile) { - return null; - } - */ + /* + * public final void prepareNarInfo(File baseDir, MavenProject project, + * NarInfo narInfo, AbstractNarMojo mojo) throws MojoExecutionException { } + * + * public File getNarUnpackDirectory(File baseUnpackDirectory, File narFile) + * { return null; } + */ public List getConfigurations() { return new ArrayList(artifactNames.keySet()); } - + public String getArtifactName(final String configuration) { return artifactNames.get(configuration); } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Executable.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Executable.java index 2c2eaac..49757b5 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Executable.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Executable.java @@ -24,10 +24,9 @@ /** * @author Mark Donszelmann (Mark.Donszelmann@gmail.com) */ -public interface Executable -{ +public interface Executable { - boolean shouldRun(); + boolean shouldRun(); - List/* */getArgs(); + List/* */getArgs(); } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Fortran.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Fortran.java index 66467b3..b36bd4e 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Fortran.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Fortran.java @@ -24,15 +24,11 @@ * * @author Mark Donszelmann */ -public class Fortran - extends Compiler -{ - public Fortran() - { - } +public class Fortran extends Compiler { + public Fortran() { + } - public final String getLanguage() - { - return "fortran"; - } + public final String getLanguage() { + return "fortran"; + } } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/ICompiler.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/ICompiler.java index f1a6fd2..33aa8eb 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/ICompiler.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/ICompiler.java @@ -27,8 +27,7 @@ public interface ICompiler { - public abstract String getName() throws MojoFailureException, - MojoExecutionException; + public abstract String getName() throws MojoFailureException, MojoExecutionException; public abstract List/* */getSourceDirectories(String type); @@ -36,11 +35,9 @@ public abstract String getName() throws MojoFailureException, public abstract List/* */getSystemIncludePaths(); - public abstract Set getIncludes(String type) throws MojoFailureException, - MojoExecutionException; + public abstract Set getIncludes(String type) throws MojoFailureException, MojoExecutionException; - public abstract Set getExcludes(String type, ITest currentTest) throws MojoFailureException, - MojoExecutionException; + public abstract Set getExcludes(String type, ITest currentTest) throws MojoFailureException, MojoExecutionException; public abstract boolean isDebug(); @@ -50,14 +47,11 @@ public abstract Set getExcludes(String type, ITest currentTest) throws MojoFailu public abstract boolean isMultiThreaded(); - public abstract List getDefines() throws MojoFailureException, - MojoExecutionException; + public abstract List getDefines() throws MojoFailureException, MojoExecutionException; - public abstract List getUndefines() throws MojoFailureException, - MojoExecutionException; + public abstract List getUndefines() throws MojoFailureException, MojoExecutionException; - public abstract List getOptions() throws MojoFailureException, - MojoExecutionException; + public abstract List getOptions() throws MojoFailureException, MojoExecutionException; public abstract boolean isExceptions(); diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/IDL.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/IDL.java index 538bc31..706a8b1 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/IDL.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/IDL.java @@ -26,10 +26,9 @@ */ public class IDL extends Compiler { - public IDL() - { + public IDL() { } - + @Override protected String getLanguage() { return "idl"; diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/ILibrary.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/ILibrary.java index 1834925..238ddc9 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/ILibrary.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/ILibrary.java @@ -29,7 +29,7 @@ public interface ILibrary { public static final String NONE = "none"; // no library produced public abstract String getType(); - + public abstract boolean linkCPP(); } \ No newline at end of file diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/ILinker.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/ILinker.java index 5560f0a..3b1053e 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/ILinker.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/ILinker.java @@ -32,13 +32,10 @@ public interface ILinker { public abstract boolean isMap(); - public abstract List getOptions() throws MojoFailureException, - MojoExecutionException; + public abstract List getOptions() throws MojoFailureException, MojoExecutionException; - public abstract List getLibs() throws MojoFailureException, - MojoExecutionException; + public abstract List getLibs() throws MojoFailureException, MojoExecutionException; - public abstract List getSysLibs() throws MojoFailureException, - MojoExecutionException; + public abstract List getSysLibs() throws MojoFailureException, MojoExecutionException; } \ No newline at end of file diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/INarCompileMojo.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/INarCompileMojo.java index f505d53..e8cc52d 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/INarCompileMojo.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/INarCompileMojo.java @@ -27,40 +27,35 @@ public interface INarCompileMojo { public abstract void validate() throws MojoFailureException, MojoExecutionException; - + public abstract String getOS(); public abstract boolean isSkip(); - + public abstract String getOutput(String type) throws MojoFailureException, MojoExecutionException; - + public abstract List getNarArtifacts(); - + public abstract ILinker getLinker(); - + public abstract List/* */getLibraries(); - + public abstract List/* */getTests(); public abstract ICompiler getC(); - + public abstract ICompiler getCpp(); - + public abstract List/* */getJavahIncludePaths(); - public abstract List/* */getJavaIncludePaths() - throws MojoExecutionException, MojoFailureException; + public abstract List/* */getJavaIncludePaths() throws MojoExecutionException, MojoFailureException; - public abstract List/* */getDependencyIncludePaths() - throws MojoExecutionException, MojoFailureException; + public abstract List/* */getDependencyIncludePaths() throws MojoExecutionException, MojoFailureException; - public abstract List/* */getDependencyLibs(String type, ITest test) - throws MojoExecutionException, MojoFailureException; + public abstract List/* */getDependencyLibs(String type, ITest test) throws MojoExecutionException, MojoFailureException; - public abstract List/* */getDependencySysLibs(String type) - throws MojoExecutionException, MojoFailureException; + public abstract List/* */getDependencySysLibs(String type) throws MojoExecutionException, MojoFailureException; - public abstract List/* */getDependencyOptions(String type) - throws MojoExecutionException, MojoFailureException; + public abstract List/* */getDependencyOptions(String type) throws MojoExecutionException, MojoFailureException; } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/ITest.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/ITest.java index e1afc4e..117463a 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/ITest.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/ITest.java @@ -21,11 +21,10 @@ import org.apache.maven.plugin.MojoFailureException; - public interface ITest extends Executable { public abstract String getName() throws MojoFailureException; - + public abstract String getLink(); } \ No newline at end of file diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Java.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Java.java index 7e320d0..ceeb3a7 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Java.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Java.java @@ -35,91 +35,79 @@ * * @author Mark Donszelmann */ -public class Java -{ +public class Java { - /** - * Add Java includes to includepath - * - * @parameter default-value="false" - * @required - */ - private boolean include = false; + /** + * Add Java includes to includepath + * + * @parameter default-value="false" + * @required + */ + private boolean include = false; - /** - * Java Include Paths, relative to a derived ${java.home}. Defaults to: "${java.home}/include" and - * "${java.home}/include/os-specific". - * - * @parameter default-value="" - */ - private List includePaths; + /** + * Java Include Paths, relative to a derived ${java.home}. Defaults to: + * "${java.home}/include" and "${java.home}/include/os-specific". + * + * @parameter default-value="" + */ + private List includePaths; - /** - * Add Java Runtime to linker - * - * @parameter default-value="false" - * @required - */ - private boolean link = false; + /** + * Add Java Runtime to linker + * + * @parameter default-value="false" + * @required + */ + private boolean link = false; - /** - * Relative path from derived ${java.home} to the java runtime to link with Defaults to Architecture-OS-Linker - * specific value. FIXME table missing - * - * @parameter default-value="" - */ - private String runtimeDirectory; + /** + * Relative path from derived ${java.home} to the java runtime to link with + * Defaults to Architecture-OS-Linker specific value. FIXME table missing + * + * @parameter default-value="" + */ + private String runtimeDirectory; - /** - * Name of the runtime - * - * @parameter default-value="jvm" - */ - private String runtime = "jvm"; + /** + * Name of the runtime + * + * @parameter default-value="jvm" + */ + private String runtime = "jvm"; - private AbstractCompileMojo mojo; + private AbstractCompileMojo mojo; - public Java() - { - } + public Java() { + } - public final void setAbstractCompileMojo( AbstractCompileMojo mojo ) - { - this.mojo = mojo; - } + public final void setAbstractCompileMojo(AbstractCompileMojo mojo) { + this.mojo = mojo; + } - public void setInclude(boolean include) { - this.include = include; - } - - public final List /**/ getIncludePaths( ) - throws MojoFailureException, MojoExecutionException - { - List jIncludePaths = new ArrayList(); - if ( include ) - { - if ( includePaths != null ) - { - for ( Iterator i = includePaths.iterator(); i.hasNext(); ) - { - String path = (String) i.next(); - jIncludePaths.add( new File( mojo.getJavaHome( mojo.getAOL() ), path ).getPath() ); - } - } - else - { - String prefix = mojo.getAOL().getKey() + ".java."; - String includes = mojo.getNarProperties().getProperty( prefix + "include" ); - if ( includes != null ) - { - String[] path = includes.split( ";" ); - for ( int i = 0; i < path.length; i++ ) - { - jIncludePaths.add(new File( mojo.getJavaHome( mojo.getAOL() ), path[i] ).getPath() ); - } - } - } - } - return jIncludePaths; - } + public void setInclude(boolean include) { + this.include = include; + } + + public final List /* */getIncludePaths() throws MojoFailureException, MojoExecutionException { + List jIncludePaths = new ArrayList(); + if (include) { + if (includePaths != null) { + for (Iterator i = includePaths.iterator(); i.hasNext();) { + String path = (String) i.next(); + jIncludePaths.add(new File(mojo.getJavaHome(mojo.getAOL()), path).getPath()); + } + } else { + String prefix = mojo.getAOL().getKey() + ".java."; + String includes = mojo.getNarProperties().getProperty(prefix + "include"); + if (includes != null) { + String[] path = includes.split(";"); + for (int i = 0; i < path.length; i++) { + jIncludePaths.add(new File(mojo.getJavaHome(mojo.getAOL()), path[i]).getPath()); + } + } + } + } + return jIncludePaths; + } } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Javah.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Javah.java index c2d3c55..5e3dc15 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Javah.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Javah.java @@ -35,202 +35,179 @@ * * @author Mark Donszelmann */ -public class Javah -{ - - /** - * Javah command to run. - * - * @parameter default-value="javah" - */ - private String name = "javah"; - - /** - * Add boot class paths. By default none. - * - * @parameter - */ - private List/* */bootClassPaths = new ArrayList(); - - /** - * Add class paths. By default the classDirectory directory is included and all dependent classes. - * - * @parameter - */ - private List/* */classPaths = new ArrayList(); - - /** - * The target directory into which to generate the output. - * - * @parameter default-value="${project.build.directory}/nar/javah-include" - * @required - */ - private File jniDirectory; - - /** - * The class directory to scan for class files with native interfaces. - * - * @parameter default-value="${project.build.directory}/classes" - * @required - */ - private File classDirectory; - - /** - * The set of files/patterns to include Defaults to "**\/*.class" - * - * @parameter - */ - private Set includes = new HashSet(); - - /** - * A list of exclusion filters. - * - * @parameter - */ - private Set excludes = new HashSet(); - - /** - * A list of class names e.g. from java.sql.* that are also passed to javah. - * - * @parameter - */ - private Set extraClasses = new HashSet(); - - /** - * The granularity in milliseconds of the last modification date for testing whether a source needs recompilation - * - * @parameter default-value="0" - * @required - */ - private int staleMillis = 0; - - /** - * The directory to store the timestampfile for the processed aid files. Defaults to jniDirectory. - * - * @parameter - */ - private File timestampDirectory; - - /** - * The timestampfile for the processed class files. Defaults to name of javah. - * - * @parameter - */ - private File timestampFile; - - private AbstractNarMojo mojo; - - public Javah() - { - } - - public final void setAbstractCompileMojo( AbstractNarMojo abstractNarMojo ) - { - this.mojo = abstractNarMojo; - } - - protected final List getClassPaths() - throws MojoExecutionException - { - if ( classPaths.isEmpty() ) - { - try - { - classPaths.addAll( mojo.getMavenProject().getCompileClasspathElements() ); - } - catch ( DependencyResolutionRequiredException e ) - { - throw new MojoExecutionException( "JAVAH, cannot get classpath", e ); - } - } - return classPaths; - } - - protected final File getJniDirectory() - { - if ( jniDirectory == null ) - { - jniDirectory = new File( mojo.getMavenProject().getBuild().getDirectory(), "nar/javah-include" ); - } - return jniDirectory; - } - - protected final File getClassDirectory() - { - if ( classDirectory == null ) - { - classDirectory = new File( mojo.getMavenProject().getBuild().getDirectory(), "classes" ); - } - return classDirectory; - } - - protected final Set getIncludes() - { - if ( includes.isEmpty() ) - { - includes.add( "**/*.class" ); - } - return includes; - } - - protected final File getTimestampDirectory() - { - if ( timestampDirectory == null ) - { - timestampDirectory = getJniDirectory(); - } - return timestampDirectory; - } - - protected final File getTimestampFile() - { - if ( timestampFile == null ) - { - timestampFile = new File( name ); - } - return timestampFile; - } - - private String[] generateArgs( Set/* */classes ) - throws MojoExecutionException - { - - List args = new ArrayList(); - - if ( !bootClassPaths.isEmpty() ) - { - args.add( "-bootclasspath" ); - args.add( StringUtils.join( bootClassPaths.iterator(), File.pathSeparator ) ); - } - - args.add( "-classpath" ); - args.add( StringUtils.join( getClassPaths().iterator(), File.pathSeparator ) ); - - args.add( "-d" ); - args.add( getJniDirectory().getPath() ); - - if ( mojo.getLog().isDebugEnabled() ) - { - args.add( "-verbose" ); - } - - if ( classes != null ) - { - for ( Iterator i = classes.iterator(); i.hasNext(); ) - { - args.add( i.next() ); - } - } - - if (extraClasses != null) - { - for ( Iterator i = extraClasses.iterator(); i.hasNext(); ) - { - args.add( i.next() ); - } - } - - return (String[]) args.toArray( new String[args.size()] ); - } - +public class Javah { + + /** + * Javah command to run. + * + * @parameter default-value="javah" + */ + private String name = "javah"; + + /** + * Add boot class paths. By default none. + * + * @parameter + */ + private List/* */bootClassPaths = new ArrayList(); + + /** + * Add class paths. By default the classDirectory directory is included and + * all dependent classes. + * + * @parameter + */ + private List/* */classPaths = new ArrayList(); + + /** + * The target directory into which to generate the output. + * + * @parameter default-value="${project.build.directory}/nar/javah-include" + * @required + */ + private File jniDirectory; + + /** + * The class directory to scan for class files with native interfaces. + * + * @parameter default-value="${project.build.directory}/classes" + * @required + */ + private File classDirectory; + + /** + * The set of files/patterns to include Defaults to "**\/*.class" + * + * @parameter + */ + private Set includes = new HashSet(); + + /** + * A list of exclusion filters. + * + * @parameter + */ + private Set excludes = new HashSet(); + + /** + * A list of class names e.g. from java.sql.* that are also passed to javah. + * + * @parameter + */ + private Set extraClasses = new HashSet(); + + /** + * The granularity in milliseconds of the last modification date for testing + * whether a source needs recompilation + * + * @parameter default-value="0" + * @required + */ + private int staleMillis = 0; + + /** + * The directory to store the timestampfile for the processed aid files. + * Defaults to jniDirectory. + * + * @parameter + */ + private File timestampDirectory; + + /** + * The timestampfile for the processed class files. Defaults to name of + * javah. + * + * @parameter + */ + private File timestampFile; + + private AbstractNarMojo mojo; + + public Javah() { + } + + public final void setAbstractCompileMojo(AbstractNarMojo abstractNarMojo) { + this.mojo = abstractNarMojo; + } + + protected final List getClassPaths() throws MojoExecutionException { + if (classPaths.isEmpty()) { + try { + classPaths.addAll(mojo.getMavenProject().getCompileClasspathElements()); + } catch (DependencyResolutionRequiredException e) { + throw new MojoExecutionException("JAVAH, cannot get classpath", e); + } + } + return classPaths; + } + + protected final File getJniDirectory() { + if (jniDirectory == null) { + jniDirectory = new File(mojo.getMavenProject().getBuild().getDirectory(), "nar/javah-include"); + } + return jniDirectory; + } + + protected final File getClassDirectory() { + if (classDirectory == null) { + classDirectory = new File(mojo.getMavenProject().getBuild().getDirectory(), "classes"); + } + return classDirectory; + } + + protected final Set getIncludes() { + if (includes.isEmpty()) { + includes.add("**/*.class"); + } + return includes; + } + + protected final File getTimestampDirectory() { + if (timestampDirectory == null) { + timestampDirectory = getJniDirectory(); + } + return timestampDirectory; + } + + protected final File getTimestampFile() { + if (timestampFile == null) { + timestampFile = new File(name); + } + return timestampFile; + } + + private String[] generateArgs(Set/* */classes) throws MojoExecutionException { + + List args = new ArrayList(); + + if (!bootClassPaths.isEmpty()) { + args.add("-bootclasspath"); + args.add(StringUtils.join(bootClassPaths.iterator(), File.pathSeparator)); + } + + args.add("-classpath"); + args.add(StringUtils.join(getClassPaths().iterator(), File.pathSeparator)); + + args.add("-d"); + args.add(getJniDirectory().getPath()); + + if (mojo.getLog().isDebugEnabled()) { + args.add("-verbose"); + } + + if (classes != null) { + for (Iterator i = classes.iterator(); i.hasNext();) { + args.add(i.next()); + } + } + + if (extraClasses != null) { + for (Iterator i = extraClasses.iterator(); i.hasNext();) { + args.add(i.next()); + } + } + + return (String[]) args.toArray(new String[args.size()]); + } + } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Lib.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Lib.java index 8a3638c..1e37144 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Lib.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Lib.java @@ -35,11 +35,11 @@ * * @author Mark Donszelmann */ -public class Lib implements ILib -{ +public class Lib implements ILib { /** - * Name of the library, or a dependency groupId:artifactId if this library contains sublibraries + * Name of the library, or a dependency groupId:artifactId if this library + * contains sublibraries * * @parameter default-value="" * @required @@ -69,21 +69,27 @@ public class Lib implements ILib */ private List/* */libs; - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see com.github.maven_nar.ILib#getType() */ public String getType() { return type; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see com.github.maven_nar.ILib#getDirectory() */ public File getDirectory() { return directory; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see com.github.maven_nar.ILib#getName() */ public String getName() { @@ -101,6 +107,5 @@ protected void setType(String type) { protected void setDirectory(File directory) { this.directory = directory; } - - + } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Library.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Library.java index 98f9a8d..5486396 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Library.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Library.java @@ -30,143 +30,136 @@ * * @author Mark Donszelmann */ -public class Library - implements Executable, ILibrary -{ - - /** - * Type of the library to generate. Possible choices are: "plugin", "shared", "static", "jni" or "executable". - * Defaults to "shared". - * - * @parameter default-value="" - */ - private String type = SHARED; - - /** - * Type of subsystem to generate: "gui", "console", "other". Defaults to "console". - * - * @parameter default-value="" - */ - private String subSystem = "console"; - - /** - * Link with stdcpp if necessary Defaults to true. - * - * @parameter default-value="" - */ - private boolean linkCPP = true; - - /** - * Link with fortran runtime if necessary Defaults to false. - * - * @parameter default-value="" - */ - private boolean linkFortran = false; - - /** - * Link with fortran startup, so that the gcc linker can find the "main" of fortran. Defaults to false. - * - * @parameter default-value="" - */ - private boolean linkFortranMain = false; - - /** - * If specified will create the NarSystem class with methods to load a JNI library. - * - * @parameter default-value="" - */ - private String narSystemPackage = null; - - /** - * Name of the NarSystem class - * - * @parameter default-value="NarSystem" - * @required - */ - private String narSystemName = "NarSystem"; - - /** - * The target directory into which to generate the output. - * - * @parameter default-value="${project.build.dir}/nar/nar-generated" - * @required - */ - private String narSystemDirectory = "nar-generated"; - - /** - * When true and if type is "executable" run this executable. Defaults to false; - * - * @parameter default-value="" - */ - private boolean run = false; - - /** - * Arguments to be used for running this executable. Defaults to empty list. This option is only used if run=true - * and type=executable. - * - * @parameter default-value="" - */ - private List/* */args = new ArrayList(); - - /* (non-Javadoc) +public class Library implements Executable, ILibrary { + + /** + * Type of the library to generate. Possible choices are: "plugin", + * "shared", "static", "jni" or "executable". Defaults to "shared". + * + * @parameter default-value="" + */ + private String type = SHARED; + + /** + * Type of subsystem to generate: "gui", "console", "other". Defaults to + * "console". + * + * @parameter default-value="" + */ + private String subSystem = "console"; + + /** + * Link with stdcpp if necessary Defaults to true. + * + * @parameter default-value="" + */ + private boolean linkCPP = true; + + /** + * Link with fortran runtime if necessary Defaults to false. + * + * @parameter default-value="" + */ + private boolean linkFortran = false; + + /** + * Link with fortran startup, so that the gcc linker can find the "main" of + * fortran. Defaults to false. + * + * @parameter default-value="" + */ + private boolean linkFortranMain = false; + + /** + * If specified will create the NarSystem class with methods to load a JNI + * library. + * + * @parameter default-value="" + */ + private String narSystemPackage = null; + + /** + * Name of the NarSystem class + * + * @parameter default-value="NarSystem" + * @required + */ + private String narSystemName = "NarSystem"; + + /** + * The target directory into which to generate the output. + * + * @parameter default-value="${project.build.dir}/nar/nar-generated" + * @required + */ + private String narSystemDirectory = "nar-generated"; + + /** + * When true and if type is "executable" run this executable. Defaults to + * false; + * + * @parameter default-value="" + */ + private boolean run = false; + + /** + * Arguments to be used for running this executable. Defaults to empty list. + * This option is only used if run=true and type=executable. + * + * @parameter default-value="" + */ + private List/* */args = new ArrayList(); + + /* + * (non-Javadoc) + * * @see com.github.maven_nar.ILibrary#getType() */ - public final String getType() - { - return type; - } - - public final boolean linkCPP() - { - return linkCPP; - } - - public final boolean linkFortran() - { - return linkFortran; - } - - public final boolean linkFortranMain() - { - return linkFortranMain; - } - - public final String getNarSystemPackage() - { - return narSystemPackage; - } - - public final boolean shouldRun() - { - return run; - } - - public final List/* */getArgs() - { - return args; - } - - public final String getNarSystemName() - { - return narSystemName; - } - - public final String getNarSystemDirectory() - { - return narSystemDirectory; - } - - // FIXME incomplete - public final String toString() - { - StringBuffer sb = new StringBuffer( "Library: " ); - sb.append( "type: " ); - sb.append( getType() ); - return sb.toString(); - } - - public String getSubSystem() - { - return subSystem; - } + public final String getType() { + return type; + } + + public final boolean linkCPP() { + return linkCPP; + } + + public final boolean linkFortran() { + return linkFortran; + } + + public final boolean linkFortranMain() { + return linkFortranMain; + } + + public final String getNarSystemPackage() { + return narSystemPackage; + } + + public final boolean shouldRun() { + return run; + } + + public final List/* */getArgs() { + return args; + } + + public final String getNarSystemName() { + return narSystemName; + } + + public final String getNarSystemDirectory() { + return narSystemDirectory; + } + + // FIXME incomplete + public final String toString() { + StringBuffer sb = new StringBuffer("Library: "); + sb.append("type: "); + sb.append(getType()); + return sb.toString(); + } + + public String getSubSystem() { + return subSystem; + } } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Linker.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Linker.java index 939a48c..b447144 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Linker.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Linker.java @@ -44,406 +44,368 @@ * * @author Mark Donszelmann */ -public class Linker implements ILinker -{ - - /** - * The Linker Some choices are: "msvc", "g++", "CC", "icpc", ... Default is Architecture-OS-Linker specific: FIXME: - * table missing - * - * @parameter default-value="" - */ - private String name; - - /** - * Path location of the linker tool - * - * @parameter default-value="" - */ - private String toolPath; - - /** - * Enables or disables incremental linking. - * - * @parameter default-value="false" - * @required - */ - private boolean incremental = false; - - /** - * Enables or disables the production of a map file. - * - * @parameter default-value="false" - * @required - */ - private boolean map = false; - - /** - * Options for the linker Defaults to Architecture-OS-Linker specific values. FIXME table missing - * - * @parameter default-value="" - */ - private List options; - - /** - * Options for the linker as a whitespace separated list. Defaults to Architecture-OS-Linker specific values. Will - * work in combination with <options>. - * - * @parameter default-value="" - */ - private String optionSet; - - /** - * Clears default options - * - * @parameter default-value="false" - * @required - */ - private boolean clearDefaultOptions; - - /** - * Adds libraries to the linker. - * - * @parameter default-value="" - */ - private List/* */libs; - - /** - * Adds libraries to the linker. Will work in combination with <libs>. The format is comma separated, - * colon-delimited values (name:type:dir), like "myLib:shared:/home/me/libs/, otherLib:static:/some/path". - * - * @parameter default-value="" - */ - private String libSet; - - /** - * Adds system libraries to the linker. - * - * @parameter default-value="" - */ - private List/* */sysLibs; - - /** - * Adds system libraries to the linker. Will work in combination with <sysLibs>. The format is comma - * separated, colon-delimited values (name:type), like "dl:shared, pthread:shared". - * - * @parameter default-value="" - */ - private String sysLibSet; - - /** - *

- * Specifies the link ordering of libraries that come from nar dependencies. The format is a comma separated list of - * dependency names, given as groupId:artifactId. - *

- *

- * Example: <narDependencyLibOrder>someGroup:myProduct, other.group:productB<narDependencyLibOrder> - *

- * - * @parameter default-value="" - */ - private String narDependencyLibOrder; - - private final Log log; - - private AbstractCompileMojo mojo; - - public Linker() - { - // default constructor for use as TAG - this( null ); - } - - public Linker( final Log log ) - { - this.log = log; - } - - /** - * For use with specific named linker. - * - * @param name - */ - public Linker( String name, final Log log ) - { - this.name = name; - this.log = log; - } - - public final void setAbstractCompileMojo( AbstractCompileMojo mojo ) - { - this.mojo = mojo; - } - - /* (non-Javadoc) +public class Linker implements ILinker { + + /** + * The Linker Some choices are: "msvc", "g++", "CC", "icpc", ... Default is + * Architecture-OS-Linker specific: FIXME: table missing + * + * @parameter default-value="" + */ + private String name; + + /** + * Path location of the linker tool + * + * @parameter default-value="" + */ + private String toolPath; + + /** + * Enables or disables incremental linking. + * + * @parameter default-value="false" + * @required + */ + private boolean incremental = false; + + /** + * Enables or disables the production of a map file. + * + * @parameter default-value="false" + * @required + */ + private boolean map = false; + + /** + * Options for the linker Defaults to Architecture-OS-Linker specific + * values. FIXME table missing + * + * @parameter default-value="" + */ + private List options; + + /** + * Options for the linker as a whitespace separated list. Defaults to + * Architecture-OS-Linker specific values. Will work in combination with + * <options>. + * + * @parameter default-value="" + */ + private String optionSet; + + /** + * Clears default options + * + * @parameter default-value="false" + * @required + */ + private boolean clearDefaultOptions; + + /** + * Adds libraries to the linker. + * + * @parameter default-value="" + */ + private List/* */libs; + + /** + * Adds libraries to the linker. Will work in combination with <libs>. + * The format is comma separated, colon-delimited values (name:type:dir), + * like "myLib:shared:/home/me/libs/, otherLib:static:/some/path". + * + * @parameter default-value="" + */ + private String libSet; + + /** + * Adds system libraries to the linker. + * + * @parameter default-value="" + */ + private List/* */sysLibs; + + /** + * Adds system libraries to the linker. Will work in combination with + * <sysLibs>. The format is comma separated, colon-delimited values + * (name:type), like "dl:shared, pthread:shared". + * + * @parameter default-value="" + */ + private String sysLibSet; + + /** + *

+ * Specifies the link ordering of libraries that come from nar dependencies. + * The format is a comma separated list of dependency names, given as + * groupId:artifactId. + *

+ *

+ * Example: <narDependencyLibOrder>someGroup:myProduct, + * other.group:productB<narDependencyLibOrder> + *

+ * + * @parameter default-value="" + */ + private String narDependencyLibOrder; + + private final Log log; + + private AbstractCompileMojo mojo; + + public Linker() { + // default constructor for use as TAG + this(null); + } + + public Linker(final Log log) { + this.log = log; + } + + /** + * For use with specific named linker. + * + * @param name + */ + public Linker(String name, final Log log) { + this.name = name; + this.log = log; + } + + public final void setAbstractCompileMojo(AbstractCompileMojo mojo) { + this.mojo = mojo; + } + + /* + * (non-Javadoc) + * * @see com.github.maven_nar.ILinker#getName() */ - public final String getName() - { - return name; - } - - public final String getName( NarProperties properties, String prefix ) - throws MojoFailureException, MojoExecutionException - { - if ( ( name == null ) && ( properties != null ) && ( prefix != null ) ) - { - name = properties.getProperty( prefix + "linker" ); - } - if ( name == null ) - { - throw new MojoExecutionException( "NAR: One of two things may be wrong here:\n\n" - + "1. tag is missing inside the tag of your NAR configuration\n\n" - + "2. no linker is defined in the aol.properties file for '" + prefix + "linker'\n" ); - } - return name; - } - - public final String getVersion() - throws MojoFailureException, MojoExecutionException - { - if ( name == null ) - { - throw new MojoFailureException( "Cannot deduce linker version if name is null" ); - } - - String version = null; - - TextStream out = new StringTextStream(); - TextStream err = new StringTextStream(); - TextStream dbg = new StringTextStream(); - - if ( name.equals( "g++" ) || name.equals( "gcc" ) ) - { - NarUtil.runCommand( "gcc", new String[] { "--version" }, null, null, out, err, dbg, log ); - Pattern p = Pattern.compile( "\\d+\\.\\d+\\.\\d+" ); - Matcher m = p.matcher( out.toString() ); - if ( m.find() ) - { - version = m.group( 0 ); - } - } - else if ( name.equals( "msvc" ) ) - { - NarUtil.runCommand( "link", new String[] { "/?" }, null, null, out, err, dbg, log, true ); - Pattern p = Pattern.compile( "\\d+\\.\\d+\\.\\d+(\\.\\d+)?" ); - Matcher m = p.matcher( out.toString() ); - if ( m.find() ) - { - version = m.group( 0 ); - } - } - else if ( name.equals( "icc" ) || name.equals( "icpc" ) ) - { - NarUtil.runCommand( "icc", new String[] { "--version" }, null, null, out, err, dbg, log ); - Pattern p = Pattern.compile( "\\d+\\.\\d+" ); - Matcher m = p.matcher( out.toString() ); - if ( m.find() ) - { - version = m.group( 0 ); - } - } - else if ( name.equals( "icl" ) ) - { - NarUtil.runCommand( "icl", new String[] { "/QV" }, null, null, out, err, dbg, log ); - Pattern p = Pattern.compile( "\\d+\\.\\d+" ); - Matcher m = p.matcher( err.toString() ); - if ( m.find() ) - { - version = m.group( 0 ); - } - } - else if ( name.equals( "CC" ) ) - { - NarUtil.runCommand( "CC", new String[] { "-V" }, null, null, out, err, dbg, log ); - Pattern p = Pattern.compile( "\\d+\\.d+" ); - Matcher m = p.matcher( err.toString() ); - if ( m.find() ) - { - version = m.group( 0 ); - } - } - else - { - throw new MojoFailureException( "Cannot find version number for linker '" + name + "'" ); - } - - if (version == null) { - throw new MojoFailureException( "Cannot deduce version number from: " + out.toString() ); - } - return version; - } - - protected final String getPrefix() - throws MojoFailureException, MojoExecutionException - { - return mojo.getAOL().getKey() + ".linker."; - } - - /* (non-Javadoc) + public final String getName() { + return name; + } + + public final String getName(NarProperties properties, String prefix) throws MojoFailureException, MojoExecutionException { + if ((name == null) && (properties != null) && (prefix != null)) { + name = properties.getProperty(prefix + "linker"); + } + if (name == null) { + throw new MojoExecutionException("NAR: One of two things may be wrong here:\n\n" + + "1. tag is missing inside the tag of your NAR configuration\n\n" + + "2. no linker is defined in the aol.properties file for '" + prefix + "linker'\n"); + } + return name; + } + + public final String getVersion() throws MojoFailureException, MojoExecutionException { + if (name == null) { + throw new MojoFailureException("Cannot deduce linker version if name is null"); + } + + String version = null; + + TextStream out = new StringTextStream(); + TextStream err = new StringTextStream(); + TextStream dbg = new StringTextStream(); + + if (name.equals("g++") || name.equals("gcc")) { + NarUtil.runCommand("gcc", new String[] { "--version" }, null, null, out, err, dbg, log); + Pattern p = Pattern.compile("\\d+\\.\\d+\\.\\d+"); + Matcher m = p.matcher(out.toString()); + if (m.find()) { + version = m.group(0); + } + } else if (name.equals("msvc")) { + NarUtil.runCommand("link", new String[] { "/?" }, null, null, out, err, dbg, log, true); + Pattern p = Pattern.compile("\\d+\\.\\d+\\.\\d+(\\.\\d+)?"); + Matcher m = p.matcher(out.toString()); + if (m.find()) { + version = m.group(0); + } + } else if (name.equals("icc") || name.equals("icpc")) { + NarUtil.runCommand("icc", new String[] { "--version" }, null, null, out, err, dbg, log); + Pattern p = Pattern.compile("\\d+\\.\\d+"); + Matcher m = p.matcher(out.toString()); + if (m.find()) { + version = m.group(0); + } + } else if (name.equals("icl")) { + NarUtil.runCommand("icl", new String[] { "/QV" }, null, null, out, err, dbg, log); + Pattern p = Pattern.compile("\\d+\\.\\d+"); + Matcher m = p.matcher(err.toString()); + if (m.find()) { + version = m.group(0); + } + } else if (name.equals("CC")) { + NarUtil.runCommand("CC", new String[] { "-V" }, null, null, out, err, dbg, log); + Pattern p = Pattern.compile("\\d+\\.d+"); + Matcher m = p.matcher(err.toString()); + if (m.find()) { + version = m.group(0); + } + } else { + throw new MojoFailureException("Cannot find version number for linker '" + name + "'"); + } + + if (version == null) { + throw new MojoFailureException("Cannot deduce version number from: " + out.toString()); + } + return version; + } + + protected final String getPrefix() throws MojoFailureException, MojoExecutionException { + return mojo.getAOL().getKey() + ".linker."; + } + + /* + * (non-Javadoc) + * * @see com.github.maven_nar.ILinker#isIncremental() */ - public boolean isIncremental() { + public boolean isIncremental() { return incremental; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see com.github.maven_nar.ILinker#isMap() */ public boolean isMap() { return map; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see com.github.maven_nar.ILinker#getOptions() */ public List getOptions() throws MojoFailureException, MojoExecutionException { List optionList = new ArrayList(); - if ( options != null ) - { - optionList.addAll(options); - } - - if ( optionSet != null ) - { - - String[] opts = optionSet.split( "\\s" ); - - for ( int i = 0; i < opts.length; i++ ) - { - - optionList.add( opts[i] ); - } - } - - if ( !clearDefaultOptions ) - { - String option = mojo.getNarProperties().getProperty( getPrefix() + "options" ); - if ( option != null ) - { - String[] opt = option.split( " " ); - for ( int i = 0; i < opt.length; i++ ) - { - optionList.add( opt[i] ); - } - } - } - return optionList; + if (options != null) { + optionList.addAll(options); + } + + if (optionSet != null) { + + String[] opts = optionSet.split("\\s"); + + for (int i = 0; i < opts.length; i++) { + + optionList.add(opts[i]); + } + } + + if (!clearDefaultOptions) { + String option = mojo.getNarProperties().getProperty(getPrefix() + "options"); + if (option != null) { + String[] opt = option.split(" "); + for (int i = 0; i < opt.length; i++) { + optionList.add(opt[i]); + } + } + } + return optionList; + } + + private List buildLibList(String libraryList) { + List libList = new ArrayList(); + if (libraryList == null) { + return libList; + } + + String[] lib = libraryList.split(","); + + for (int i = 0; i < lib.length; i++) { + + String[] libInfo = lib[i].trim().split(":", 3); + + String[] libNames = new NarUtil.StringArrayBuilder(libInfo[0]).getValue(); + for (int j = 0; j < libNames.length; ++j) { + Lib library = new Lib(); + library.setName(libNames[j]); + library.setType(null); + if (libInfo.length > 1) { + library.setType(libInfo[1]); + if (libInfo.length > 2) { + library.setDirectory(new File(libInfo[2])); + } + } + libList.add(library); + } + } + return libList; } - - private List buildLibList( String libraryList ) - { - List libList = new ArrayList(); - if ( libraryList == null ) - { - return libList; - } - - String[] lib = libraryList.split( "," ); - - for ( int i = 0; i < lib.length; i++ ) - { - - String[] libInfo = lib[i].trim().split( ":", 3 ); - - String[] libNames = new NarUtil.StringArrayBuilder( libInfo[0] ).getValue(); - for ( int j = 0; j < libNames.length; ++j) { - Lib library = new Lib(); - library.setName( libNames[j] ); - library.setType(null); - if ( libInfo.length > 1 ) - { - library.setType( libInfo[1] ); - if ( libInfo.length > 2 ) - { - library.setDirectory( new File( libInfo[2] ) ); - } - } - libList.add(library); - } - } - return libList; - } - - private List buildSysLibList( String libraryList ) - { - List libList = new ArrayList(); - if ( libraryList == null ) - { - return libList; - } - - String[] lib = libraryList.split( "," ); - - for ( int i = 0; i < lib.length; i++ ) - { - - String[] libInfo = lib[i].trim().split( ":", 3 ); - - String[] libNames = new NarUtil.StringArrayBuilder( libInfo[0] ).getValue(); - for ( int j = 0; j < libNames.length; ++j) { - SysLib library = new SysLib(); - library.setName( libNames[j] ); - library.setType(null); - if ( libInfo.length > 1 ) - { - library.setType( libInfo[1] ); - } - libList.add(library); - } - } - return libList; - } - - /* (non-Javadoc) + + private List buildSysLibList(String libraryList) { + List libList = new ArrayList(); + if (libraryList == null) { + return libList; + } + + String[] lib = libraryList.split(","); + + for (int i = 0; i < lib.length; i++) { + + String[] libInfo = lib[i].trim().split(":", 3); + + String[] libNames = new NarUtil.StringArrayBuilder(libInfo[0]).getValue(); + for (int j = 0; j < libNames.length; ++j) { + SysLib library = new SysLib(); + library.setName(libNames[j]); + library.setType(null); + if (libInfo.length > 1) { + library.setType(libInfo[1]); + } + libList.add(library); + } + } + return libList; + } + + /* + * (non-Javadoc) + * * @see com.github.maven_nar.ILinker#getLibs() */ - public List getLibs() throws MojoFailureException, MojoExecutionException { - List fullLibList = new ArrayList(); - if ( ( libs != null ) || ( libSet != null ) ) - { - - if ( libs != null ) - { - fullLibList.addAll(libs); - } - - if ( libSet != null ) - { - fullLibList.addAll( buildLibList( libSet ) ); - } - } - else - { - String libsList = mojo.getNarProperties().getProperty( getPrefix() + "libs" ); - fullLibList.addAll( buildLibList( libsList ) ); - } - return fullLibList; - } - - /* (non-Javadoc) + public List getLibs() throws MojoFailureException, MojoExecutionException { + List fullLibList = new ArrayList(); + if ((libs != null) || (libSet != null)) { + + if (libs != null) { + fullLibList.addAll(libs); + } + + if (libSet != null) { + fullLibList.addAll(buildLibList(libSet)); + } + } else { + String libsList = mojo.getNarProperties().getProperty(getPrefix() + "libs"); + fullLibList.addAll(buildLibList(libsList)); + } + return fullLibList; + } + + /* + * (non-Javadoc) + * * @see com.github.maven_nar.ILinker#getSysLibs() */ - public List getSysLibs() throws MojoFailureException, MojoExecutionException { - List fullSysLibList = new ArrayList(); - if ( ( sysLibs != null ) || ( sysLibSet != null ) ) - { - - if ( sysLibs != null ) - { - fullSysLibList.addAll(sysLibs); - } - - if ( sysLibSet != null ) - { - fullSysLibList.addAll( buildSysLibList( sysLibSet ) ); - } - } - else - { - String sysLibsList = mojo.getNarProperties().getProperty( getPrefix() + "sysLibs" ); - fullSysLibList.addAll( buildSysLibList( sysLibsList ) ); - } - return fullSysLibList; - } + public List getSysLibs() throws MojoFailureException, MojoExecutionException { + List fullSysLibList = new ArrayList(); + if ((sysLibs != null) || (sysLibSet != null)) { + + if (sysLibs != null) { + fullSysLibList.addAll(sysLibs); + } + + if (sysLibSet != null) { + fullSysLibList.addAll(buildSysLibList(sysLibSet)); + } + } else { + String sysLibsList = mojo.getNarProperties().getProperty(getPrefix() + "sysLibs"); + fullSysLibList.addAll(buildSysLibList(sysLibsList)); + } + return fullSysLibList; + } } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Message.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Message.java index 48188c3..e4af4d7 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Message.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Message.java @@ -24,15 +24,11 @@ * * @author Greg Domjan */ -public class Message - extends Compiler -{ - public Message() - { - } +public class Message extends Compiler { + public Message() { + } - public final String getLanguage() - { - return "mc"; - } + public final String getLanguage() { + return "mc"; + } } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarArtifact.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarArtifact.java index 87a5644..fcc6576 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarArtifact.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarArtifact.java @@ -30,38 +30,32 @@ /** * @author Mark Donszelmann */ -public class NarArtifact - extends DefaultArtifact -{ - - private NarInfo narInfo; - private NarLayout narLayout; - - public NarArtifact( Artifact dependency, NarInfo narInfo, NarLayout narLayout ) - { - super( dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersionRange(), - dependency.getScope(), dependency.getType(), dependency.getClassifier(), - dependency.getArtifactHandler(), dependency.isOptional() ); - this.setFile( dependency.getFile() ); - this.narInfo = narInfo; - this.narLayout = narLayout; - } - - public final NarInfo getNarInfo() - { - return narInfo; - } - - public final NarLayout getNarLayout() - { - return narLayout; - } - - public String getBaseFilename() { - return getArtifactId()+"-"+getBaseVersion()+"-"+getClassifier(); - } - - public final File getTargetDirectory( ) { - return getNarInfo().getTargetDirectory(); - } +public class NarArtifact extends DefaultArtifact { + + private NarInfo narInfo; + private NarLayout narLayout; + + public NarArtifact(Artifact dependency, NarInfo narInfo, NarLayout narLayout) { + super(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersionRange(), dependency.getScope(), dependency.getType(), dependency + .getClassifier(), dependency.getArtifactHandler(), dependency.isOptional()); + this.setFile(dependency.getFile()); + this.narInfo = narInfo; + this.narLayout = narLayout; + } + + public final NarInfo getNarInfo() { + return narInfo; + } + + public final NarLayout getNarLayout() { + return narLayout; + } + + public String getBaseFilename() { + return getArtifactId() + "-" + getBaseVersion() + "-" + getClassifier(); + } + + public final File getTargetDirectory() { + return getNarInfo().getTargetDirectory(); + } } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarCompileMojo.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarCompileMojo.java index a27b101..80e293c 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarCompileMojo.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarCompileMojo.java @@ -50,14 +50,14 @@ public class NarCompileMojo extends AbstractCompileMojo */ protected MavenSession session; - protected List getArtifacts() { - final Set artifacts = getMavenProject().getArtifacts(); - List returnArtifact = new ArrayList(); - for(Artifact a : artifacts) { - if (Artifact.SCOPE_COMPILE.equals(a.getScope()) || Artifact.SCOPE_PROVIDED.equals(a.getScope()) || Artifact.SCOPE_SYSTEM.equals(a.getScope())) { - returnArtifact.add(a); - } - } - return returnArtifact; - } + protected List getArtifacts() { + final Set artifacts = getMavenProject().getArtifacts(); + List returnArtifact = new ArrayList(); + for (Artifact a : artifacts) { + if (Artifact.SCOPE_COMPILE.equals(a.getScope()) || Artifact.SCOPE_PROVIDED.equals(a.getScope()) || Artifact.SCOPE_SYSTEM.equals(a.getScope())) { + returnArtifact.add(a); + } + } + return returnArtifact; + } } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarConstants.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarConstants.java index 5b88449..e348de1 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarConstants.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarConstants.java @@ -22,27 +22,26 @@ /** * @author Mark Donszelmann */ -public interface NarConstants -{ - String NAR = "nar"; - - String NAR_EXTENSION = NAR; +public interface NarConstants { + String NAR = "nar"; - String NAR_NO_ARCH = "noarch"; - - String NAR_AOL = "aol"; + String NAR_EXTENSION = NAR; - String NAR_ROLE_HINT = NAR; + String NAR_NO_ARCH = "noarch"; - String NAR_TYPE = NAR; + String NAR_AOL = "aol"; - int LOG_LEVEL_ERROR = 0; + String NAR_ROLE_HINT = NAR; - int LOG_LEVEL_WARNING = 1; + String NAR_TYPE = NAR; - int LOG_LEVEL_INFO = 2; + int LOG_LEVEL_ERROR = 0; - int LOG_LEVEL_VERBOSE = 3; + int LOG_LEVEL_WARNING = 1; - int LOG_LEVEL_DEBUG = 4; + int LOG_LEVEL_INFO = 2; + + int LOG_LEVEL_VERBOSE = 3; + + int LOG_LEVEL_DEBUG = 4; } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarFileLayout.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarFileLayout.java index 12d7779..c4d0504 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarFileLayout.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarFileLayout.java @@ -19,32 +19,30 @@ */ package com.github.maven_nar; - /** * Defines the layout inside the nar file. * * @author Mark Donszelmann (Mark.Donszelmann@gmail.com) */ -public interface NarFileLayout -{ - /** - * Specifies where libraries are stored - * - * @return - */ - String getLibDirectory(String aol, String type ); +public interface NarFileLayout { + /** + * Specifies where libraries are stored + * + * @return + */ + String getLibDirectory(String aol, String type); - /** - * Specifies where includes are stored - * - * @return - */ - String getIncludeDirectory(); + /** + * Specifies where includes are stored + * + * @return + */ + String getIncludeDirectory(); - /** - * Specifies where binaries are stored - * - * @return - */ - String getBinDirectory(String aol ); + /** + * Specifies where binaries are stored + * + * @return + */ + String getBinDirectory(String aol); } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarFileLayout10.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarFileLayout10.java index e07507e..e77647c 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarFileLayout10.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarFileLayout10.java @@ -24,34 +24,33 @@ /** * @author Mark Donszelmann (Mark.Donszelmann@gmail.com) */ -public class NarFileLayout10 - implements NarFileLayout -{ +public class NarFileLayout10 implements NarFileLayout { - /* - * (non-Javadoc) - * @see com.github.maven_nar.NarFileLayout#getIncludeDirectory() - */ - public String getIncludeDirectory() - { - return "include"; - } + /* + * (non-Javadoc) + * + * @see com.github.maven_nar.NarFileLayout#getIncludeDirectory() + */ + public String getIncludeDirectory() { + return "include"; + } - /* - * (non-Javadoc) - * @see com.github.maven_nar.NarFileLayout#getLibDirectory(java.lang.String, java.lang.String) - */ - public String getLibDirectory( String aol, String type ) - { - return "lib" + File.separator + aol + File.separator + type; - } + /* + * (non-Javadoc) + * + * @see com.github.maven_nar.NarFileLayout#getLibDirectory(java.lang.String, + * java.lang.String) + */ + public String getLibDirectory(String aol, String type) { + return "lib" + File.separator + aol + File.separator + type; + } - /* - * (non-Javadoc) - * @see com.github.maven_nar.NarFileLayout#getBinDirectory(java.lang.String) - */ - public String getBinDirectory( String aol ) - { - return "bin" + File.separator + aol; - } + /* + * (non-Javadoc) + * + * @see com.github.maven_nar.NarFileLayout#getBinDirectory(java.lang.String) + */ + public String getBinDirectory(String aol) { + return "bin" + File.separator + aol; + } } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarInfo.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarInfo.java index d1c5f9b..3ea565d 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarInfo.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarInfo.java @@ -42,246 +42,199 @@ /** * @author Mark Donszelmann */ -public class NarInfo -{ - - public static final String NAR_PROPERTIES = "nar.properties"; - - private String groupId, artifactId, version; - - private Properties info; - - private Log log; - - public NarInfo( String groupId, String artifactId, String version, Log log ) throws MojoExecutionException - { - this( groupId, artifactId, version, log, null ); - } - - public NarInfo( String groupId, String artifactId, String version, Log log, File propertiesFile ) throws MojoExecutionException - { - this.groupId = groupId; - this.artifactId = artifactId; - this.version = version; - this.log = log; - info = new Properties(); - - // Fill with general properties.nar file - if( propertiesFile != null ) - { - try - { - info.load( new FileInputStream( propertiesFile ) ); - } - catch ( FileNotFoundException e ) - { - // ignored - } - catch ( IOException e ) - { - throw new MojoExecutionException( "Problem loading "+propertiesFile, e ); - } - } - } - - public final String toString() - { - StringBuffer s = new StringBuffer( "NarInfo for " ); - s.append( groupId ); - s.append( ":" ); - s.append( artifactId ); - s.append( "-" ); - s.append( version ); - s.append( " {\n" ); - - for ( Iterator i = info.keySet().iterator(); i.hasNext(); ) - { - String key = (String) i.next(); - s.append( " " ); - s.append( key ); - s.append( "='" ); - s.append( info.getProperty( key, "" ) ); - s.append( "'\n" ); - } - - s.append( "}\n" ); - return s.toString(); - } - - public final boolean exists( File artifactFile ) - { - return getNarPropertiesURL( artifactFile ) != null; - } - - public final void read( File artifactFile ) - throws IOException - { - info.load( getNarPropertiesURL(artifactFile).openStream() ); - } - - public final void write( File dir ) - throws IOException - { - // TODO: this structure seems overly deep it already gets unpacked to own folder - classes/ - File propertiesDir = - new File( dir, "META-INF/nar/" + groupId + "/" + artifactId ); - if ( !propertiesDir.exists() ) - { - propertiesDir.mkdirs(); - } - File propertiesFile = new File( propertiesDir, NarInfo.NAR_PROPERTIES ); - writeToFile( propertiesFile ); - } - - private URL getNarPropertiesURL( File artifactFile ) - { - try - { - // artifactFile can either be a directory in a multi-module compile, - // or a JAR in the local repository. URLClassLoader can handle this for us - URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { - artifactFile.toURI().toURL() } ); - return urlClassLoader.findResource("META-INF/nar/" + groupId + "/" + artifactId + "/" + NAR_PROPERTIES ); - } - catch (MalformedURLException e) - { - log.error("Could not process artifact " + artifactFile, e); - return null; - } - } - - /** - * No binding means default binding. - * - * @param aol - * @return - */ - public final String getBinding( AOL aol, String defaultBinding ) - { - return getProperty( aol, "libs.binding", defaultBinding ); - } - - public final void setBinding( AOL aol, String value ) - { - setProperty( aol, "libs.binding", value ); - } - - public final String getOutput( AOL aol, String defaultOutput ) - { - return getProperty( aol, "output", defaultOutput ); - } - - public final void setOutput( AOL aol, String value ) - { - setProperty( aol, "output", value ); - } - - // FIXME replace with list of AttachedNarArtifacts - public final String[] getAttachedNars( AOL aol, String type ) - { - String attachedNars = getProperty( aol, NarConstants.NAR+"." + type ); - return attachedNars != null ? attachedNars.split( "," ) : null; - } - - public final void addNar( AOL aol, String type, String nar ) - { - String nars = getProperty( aol, NarConstants.NAR+"." + type ); - nars = ( nars == null ) ? nar : nars + ", " + nar; - setProperty( aol, NarConstants.NAR+"." + type, nars ); - } - - public final void setNar( AOL aol, String type, String nar ) - { - setProperty( aol, NarConstants.NAR+"." + type, nar ); - } - - public final AOL getAOL( AOL aol ) - { - return aol == null ? null : new AOL( getProperty( aol, aol.toString(), aol.toString() ) ); - } - - public final String getOptions( AOL aol ) - { - return getProperty( aol, "linker.options" ); - } - - public final String getLibs( AOL aol ) - { - // TODO: resolve output Vs libs.names - // nothing is available to set libs.names within the build. - // if there is an existing nar.properties that was hand crafter with libs.names then this would work - undocumented feature? - return getProperty( aol, "libs.names", getOutput( aol, artifactId + "-" + version ) ); - } - - public final String getSysLibs( AOL aol ) - { - return getProperty( aol, "syslibs.names" ); - } - - public final void setTargetDirectory( final File targetDirectory ) { - setProperty(null, "targetDirectory", targetDirectory.getAbsolutePath()); - } - - public final File getTargetDirectory() { - final String targetDirectory = getProperty(null, "targetDirectory"); - if (targetDirectory != null) - { - return new File(targetDirectory); - } - else - { - return null; - } - } - - public final void writeToFile( File file ) - throws IOException - { - info.store( new FileOutputStream( ( file ) ), "NAR Properties for " + groupId + "." + artifactId + "-" - + version ); - } - - private void setProperty( AOL aol, String key, String value ) - { - if ( aol == null ) - { - info.setProperty( key, value ); - } - else - { - info.setProperty( aol.toString() + "." + key, value ); - } - } - - public final String getProperty( AOL aol, String key ) - { - return getProperty( aol, key, (String) null ); - } - - public final String getProperty( AOL aol, String key, String defaultValue ) - { - if ( key == null ) - { - return defaultValue; - } - String value = info.getProperty( key, defaultValue ); - value = aol == null ? value : info.getProperty( aol.toString() + "." + key, value ); - log.debug( "getProperty(" + aol + ", " + key + ", " + defaultValue + ") = " + value ); - return value; - } - - public final int getProperty( AOL aol, String key, int defaultValue ) - { - return Integer.parseInt( getProperty( aol, key, Integer.toString( defaultValue ) ) ); - } - - public final boolean getProperty( AOL aol, String key, boolean defaultValue ) - { - return (new Boolean( getProperty( aol, key, String.valueOf( defaultValue ) ) )).booleanValue(); - } - - public final File getProperty( AOL aol, String key, File defaultValue ) - { - return new File( getProperty( aol, key, defaultValue.getPath() ) ); - } +public class NarInfo { + + public static final String NAR_PROPERTIES = "nar.properties"; + + private String groupId, artifactId, version; + + private Properties info; + + private Log log; + + public NarInfo(String groupId, String artifactId, String version, Log log) throws MojoExecutionException { + this(groupId, artifactId, version, log, null); + } + + public NarInfo(String groupId, String artifactId, String version, Log log, File propertiesFile) throws MojoExecutionException { + this.groupId = groupId; + this.artifactId = artifactId; + this.version = version; + this.log = log; + info = new Properties(); + + // Fill with general properties.nar file + if (propertiesFile != null) { + try { + info.load(new FileInputStream(propertiesFile)); + } catch (FileNotFoundException e) { + // ignored + } catch (IOException e) { + throw new MojoExecutionException("Problem loading " + propertiesFile, e); + } + } + } + + public final String toString() { + StringBuffer s = new StringBuffer("NarInfo for "); + s.append(groupId); + s.append(":"); + s.append(artifactId); + s.append("-"); + s.append(version); + s.append(" {\n"); + + for (Iterator i = info.keySet().iterator(); i.hasNext();) { + String key = (String) i.next(); + s.append(" "); + s.append(key); + s.append("='"); + s.append(info.getProperty(key, "")); + s.append("'\n"); + } + + s.append("}\n"); + return s.toString(); + } + + public final boolean exists(File artifactFile) { + return getNarPropertiesURL(artifactFile) != null; + } + + public final void read(File artifactFile) throws IOException { + info.load(getNarPropertiesURL(artifactFile).openStream()); + } + + public final void write(File dir) throws IOException { + // TODO: this structure seems overly deep it already gets unpacked to + // own folder - classes/ + File propertiesDir = new File(dir, "META-INF/nar/" + groupId + "/" + artifactId); + if (!propertiesDir.exists()) { + propertiesDir.mkdirs(); + } + File propertiesFile = new File(propertiesDir, NarInfo.NAR_PROPERTIES); + writeToFile(propertiesFile); + } + + private URL getNarPropertiesURL(File artifactFile) { + try { + // artifactFile can either be a directory in a multi-module compile, + // or a JAR in the local repository. URLClassLoader can handle this + // for us + URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { artifactFile.toURI().toURL() }); + return urlClassLoader.findResource("META-INF/nar/" + groupId + "/" + artifactId + "/" + NAR_PROPERTIES); + } catch (MalformedURLException e) { + log.error("Could not process artifact " + artifactFile, e); + return null; + } + } + + /** + * No binding means default binding. + * + * @param aol + * @return + */ + public final String getBinding(AOL aol, String defaultBinding) { + return getProperty(aol, "libs.binding", defaultBinding); + } + + public final void setBinding(AOL aol, String value) { + setProperty(aol, "libs.binding", value); + } + + public final String getOutput(AOL aol, String defaultOutput) { + return getProperty(aol, "output", defaultOutput); + } + + public final void setOutput(AOL aol, String value) { + setProperty(aol, "output", value); + } + + // FIXME replace with list of AttachedNarArtifacts + public final String[] getAttachedNars(AOL aol, String type) { + String attachedNars = getProperty(aol, NarConstants.NAR + "." + type); + return attachedNars != null ? attachedNars.split(",") : null; + } + + public final void addNar(AOL aol, String type, String nar) { + String nars = getProperty(aol, NarConstants.NAR + "." + type); + nars = (nars == null) ? nar : nars + ", " + nar; + setProperty(aol, NarConstants.NAR + "." + type, nars); + } + + public final void setNar(AOL aol, String type, String nar) { + setProperty(aol, NarConstants.NAR + "." + type, nar); + } + + public final AOL getAOL(AOL aol) { + return aol == null ? null : new AOL(getProperty(aol, aol.toString(), aol.toString())); + } + + public final String getOptions(AOL aol) { + return getProperty(aol, "linker.options"); + } + + public final String getLibs(AOL aol) { + // TODO: resolve output Vs libs.names + // nothing is available to set libs.names within the build. + // if there is an existing nar.properties that was hand crafter with + // libs.names then this would work - undocumented feature? + return getProperty(aol, "libs.names", getOutput(aol, artifactId + "-" + version)); + } + + public final String getSysLibs(AOL aol) { + return getProperty(aol, "syslibs.names"); + } + + public final void setTargetDirectory(final File targetDirectory) { + setProperty(null, "targetDirectory", targetDirectory.getAbsolutePath()); + } + + public final File getTargetDirectory() { + final String targetDirectory = getProperty(null, "targetDirectory"); + if (targetDirectory != null) { + return new File(targetDirectory); + } else { + return null; + } + } + + public final void writeToFile(File file) throws IOException { + info.store(new FileOutputStream((file)), "NAR Properties for " + groupId + "." + artifactId + "-" + version); + } + + private void setProperty(AOL aol, String key, String value) { + if (aol == null) { + info.setProperty(key, value); + } else { + info.setProperty(aol.toString() + "." + key, value); + } + } + + public final String getProperty(AOL aol, String key) { + return getProperty(aol, key, (String) null); + } + + public final String getProperty(AOL aol, String key, String defaultValue) { + if (key == null) { + return defaultValue; + } + String value = info.getProperty(key, defaultValue); + value = aol == null ? value : info.getProperty(aol.toString() + "." + key, value); + log.debug("getProperty(" + aol + ", " + key + ", " + defaultValue + ") = " + value); + return value; + } + + public final int getProperty(AOL aol, String key, int defaultValue) { + return Integer.parseInt(getProperty(aol, key, Integer.toString(defaultValue))); + } + + public final boolean getProperty(AOL aol, String key, boolean defaultValue) { + return (new Boolean(getProperty(aol, key, String.valueOf(defaultValue)))).booleanValue(); + } + + public final File getProperty(AOL aol, String key, File defaultValue) { + return new File(getProperty(aol, key, defaultValue.getPath())); + } } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarLayout.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarLayout.java index 911506a..afdcb20 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarLayout.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarLayout.java @@ -27,84 +27,80 @@ import org.apache.maven.project.MavenProject; /** - * Interface to define the layout of nar files (executables, libs, include dirs) in both the repository (local, - * unpacked) as well as in target. - * + * Interface to define the layout of nar files (executables, libs, include dirs) + * in both the repository (local, unpacked) as well as in target. + * * @author Mark Donszelmann (Mark.Donszelmann@gmail.com) */ -public interface NarLayout -{ - /** - * Specifies where all the "no architecture" specific files are stored - */ - File getNoArchDirectory( File baseDir, NarArtifact artifact ) - throws MojoExecutionException, MojoFailureException; +public interface NarLayout { + /** + * Specifies where all the "no architecture" specific files are stored + */ + File getNoArchDirectory(File baseDir, NarArtifact artifact) throws MojoExecutionException, MojoFailureException; - /** - * Specifies where all the "no architecture" specific files are stored - */ - File getNoArchDirectory( File baseDir, MavenProject project ) - throws MojoExecutionException, MojoFailureException; + /** + * Specifies where all the "no architecture" specific files are stored + */ + File getNoArchDirectory(File baseDir, MavenProject project) throws MojoExecutionException, MojoFailureException; - /** - * Specifies where libraries are stored - * - * @return - * @throws MojoExecutionException, MojoFailureException - */ - File getLibDirectory( File baseDir, NarArtifact artifact, String aol, String type ) - throws MojoExecutionException, MojoFailureException; + /** + * Specifies where libraries are stored + * + * @return + * @throws MojoExecutionException + * , MojoFailureException + */ + File getLibDirectory(File baseDir, NarArtifact artifact, String aol, String type) throws MojoExecutionException, MojoFailureException; - /** - * Specifies where libraries are stored - * - * @return - * @throws MojoExecutionException, MojoFailureException - */ - File getLibDirectory( File baseDir, MavenProject project, String aol, String type ) - throws MojoExecutionException, MojoFailureException; + /** + * Specifies where libraries are stored + * + * @return + * @throws MojoExecutionException + * , MojoFailureException + */ + File getLibDirectory(File baseDir, MavenProject project, String aol, String type) throws MojoExecutionException, MojoFailureException; - /** - * Specifies where includes are stored - * - * @return - */ - List getIncludeDirectories( File baseDir, NarArtifact artifact ) - throws MojoExecutionException, MojoFailureException; + /** + * Specifies where includes are stored + * + * @return + */ + List getIncludeDirectories(File baseDir, NarArtifact artifact) throws MojoExecutionException, MojoFailureException; - /** - * Specifies where includes are stored - * - * @return - */ - File getIncludeDirectory( File baseDir, MavenProject project ) - throws MojoExecutionException, MojoFailureException; + /** + * Specifies where includes are stored + * + * @return + */ + File getIncludeDirectory(File baseDir, MavenProject project) throws MojoExecutionException, MojoFailureException; - /** - * Specifies where binaries are stored - * - * @return - */ - File getBinDirectory( File baseDir, NarArtifact artifact, String aol ) - throws MojoExecutionException, MojoFailureException; + /** + * Specifies where binaries are stored + * + * @return + */ + File getBinDirectory(File baseDir, NarArtifact artifact, String aol) throws MojoExecutionException, MojoFailureException; - /** - * Specifies where binaries are stored - * - * @return - */ - File getBinDirectory( File baseDir, MavenProject project, String aol ) - throws MojoExecutionException, MojoFailureException; + /** + * Specifies where binaries are stored + * + * @return + */ + File getBinDirectory(File baseDir, MavenProject project, String aol) throws MojoExecutionException, MojoFailureException; - /** - * Called to attach nars to main nar/jar file. This method needs to set NarInfo accordingly so it can be included in the nar archive. - */ - //void prepareNarInfo( File baseDir, MavenProject project, NarInfo narInfo, AbstractNarMojo libraryName ) - // throws MojoExecutionException; + /** + * Called to attach nars to main nar/jar file. This method needs to set + * NarInfo accordingly so it can be included in the nar archive. + */ + // void prepareNarInfo( File baseDir, MavenProject project, NarInfo narInfo, + // AbstractNarMojo libraryName ) + // throws MojoExecutionException; - /** - * Returns the unpack directory of a specific nar file. - */ - //File getNarUnpackDirectory(File baseUnpackDirectory, AttachedNarArtifact artifact); + /** + * Returns the unpack directory of a specific nar file. + */ + // File getNarUnpackDirectory(File baseUnpackDirectory, AttachedNarArtifact + // artifact); } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarLayout20.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarLayout20.java index 9014acd..f0ff39b 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarLayout20.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarLayout20.java @@ -33,170 +33,148 @@ /** * Initial layout which expands a nar file into: - * + * *
  * nar/includue
  * nar/bin
  * nar/lib
  * 
- * - * this layout was abandoned because there is no one-to-one relation between the nar file and its directory structure. - * Therefore SNAPSHOTS could not be fully deleted when replaced. - * + * + * this layout was abandoned because there is no one-to-one relation between the + * nar file and its directory structure. Therefore SNAPSHOTS could not be fully + * deleted when replaced. + * * @author Mark Donszelmann (Mark.Donszelmann@gmail.com) */ -public class NarLayout20 - extends AbstractNarLayout -{ - private NarFileLayout fileLayout; - - public NarLayout20( Log log ) - { - super( log ); - this.fileLayout = new NarFileLayout10(); - } - - /* - * (non-Javadoc) - * @see com.github.maven_nar.NarLayout#getNoArchDirectory(java.io.File) - */ - public File getNoArchDirectory( File baseDir, NarArtifact artifact ) - throws MojoExecutionException, MojoFailureException - { - return baseDir; - } - - public File getNoArchDirectory( File baseDir, MavenProject project ) - throws MojoExecutionException, MojoFailureException - { - return baseDir; - } - - /* - * (non-Javadoc) - * @see com.github.maven_nar.NarLayout#getIncludeDirectory(java.io.File) - */ - public final List getIncludeDirectories( File baseDir, NarArtifact artifact ) - { - ArrayList includes = new ArrayList(); - includes.add( new File( baseDir, fileLayout.getIncludeDirectory() ) ); - return includes; - } - - public final File getIncludeDirectory( File baseDir, MavenProject project ) - { - return new File( baseDir, fileLayout.getIncludeDirectory() ); - } - - /* - * (non-Javadoc) - * @see com.github.maven_nar.NarLayout#getLibDir(java.io.File, com.github.maven_nar.AOL, String type) - */ - public final File getLibDirectory( File baseDir, NarArtifact artifact, String aol, String type ) - throws MojoFailureException - { - if ( type.equals( Library.EXECUTABLE ) ) - { - throw new MojoFailureException( "INTERNAL ERROR, Replace call to getLibDirectory with getBinDirectory" ); - } - - File dir = new File( baseDir, fileLayout.getLibDirectory( aol, type ) ); - return dir; - } - - /* - * (non-Javadoc) - * @see com.github.maven_nar.NarLayout#getLibDir(java.io.File, com.github.maven_nar.AOL, String type) - */ - public final File getLibDirectory( File baseDir, MavenProject project, String aol, String type ) - throws MojoFailureException - { - if ( type.equals( Library.EXECUTABLE ) ) - { - throw new MojoFailureException( "INTERNAL ERROR, Replace call to getLibDirectory with getBinDirectory" ); - } - - File dir = new File( baseDir, fileLayout.getLibDirectory( aol, type ) ); - return dir; - } - - /* - * (non-Javadoc) - * @see com.github.maven_nar.NarLayout#getBinDirectory(java.io.File, java.lang.String) - */ - public final File getBinDirectory( File baseDir, NarArtifact artifact, String aol ) - { - File dir = new File( baseDir, fileLayout.getBinDirectory( aol ) ); - return dir; - } - - /* - * (non-Javadoc) - * @see com.github.maven_nar.NarLayout#getBinDirectory(java.io.File, java.lang.String) - */ - public final File getBinDirectory( File baseDir, MavenProject project, String aol ) - { - File dir = new File( baseDir, fileLayout.getBinDirectory( aol ) ); - return dir; - } - - /* - * (non-Javadoc) - * @see com.github.maven_nar.NarLayout#attachNars(java.io.File, org.apache.maven.project.MavenProjectHelper, - * org.apache.maven.project.MavenProject, com.github.maven_nar.NarInfo) - */ - /* - public final void prepareNarInfo( File baseDir, MavenProject project, NarInfo narInfo, AbstractNarMojo mojo ) - throws MojoExecutionException - { - if ( getIncludeDirectory( baseDir, project ).exists() ) - { - narInfo.setNar( null, "noarch", project.getGroupId() + ":" + project.getArtifactId() + ":" - + NarConstants.NAR_TYPE + ":" + "noarch" ); - } - - String[] binAOL = new File( baseDir, "bin" ).list(); - for ( int i = 0; ( binAOL != null ) && ( i < binAOL.length ); i++ ) - {// TODO: chose not to apply new file naming for outfile in case of backwards compatability, may need to reconsider - narInfo.setNar( null, Library.EXECUTABLE, project.getGroupId() + ":" + project.getArtifactId() + ":" - + NarConstants.NAR_TYPE + ":" + "${aol}" + "-" + Library.EXECUTABLE ); - narInfo.setBinding( new AOL( binAOL[i] ), Library.EXECUTABLE ); - narInfo.setBinding( null, Library.EXECUTABLE ); - } - - File libDir = new File( baseDir, "lib" ); - String[] libAOL = libDir.list(); - for ( int i = 0; ( libAOL != null ) && ( i < libAOL.length ); i++ ) - { - String bindingType = null; - String[] libType = new File( libDir, libAOL[i] ).list(); - for ( int j = 0; ( libType != null ) && ( j < libType.length ); j++ ) - { - narInfo.setNar( null, libType[j], project.getGroupId() + ":" + project.getArtifactId() + ":" - + NarConstants.NAR_TYPE + ":" + "${aol}" + "-" + libType[j] ); - - // set if not set or override if SHARED - if ( ( bindingType == null ) || libType[j].equals( Library.SHARED ) ) - { - bindingType = libType[j]; - } - } - - AOL aol = new AOL( libAOL[i] ); - if ( narInfo.getBinding( aol, null ) == null ) - { - narInfo.setBinding( aol, bindingType != null ? bindingType : Library.NONE ); - } - if ( narInfo.getBinding( null, null ) == null ) - { - narInfo.setBinding( null, bindingType != null ? bindingType : Library.NONE ); - } - } - } - - public File getNarUnpackDirectory(File baseUnpackDirectory, AttachedNarArtifact artifact ) - { - return baseUnpackDirectory; - } - */ +public class NarLayout20 extends AbstractNarLayout { + private NarFileLayout fileLayout; + + public NarLayout20(Log log) { + super(log); + this.fileLayout = new NarFileLayout10(); + } + + /* + * (non-Javadoc) + * + * @see com.github.maven_nar.NarLayout#getNoArchDirectory(java.io.File) + */ + public File getNoArchDirectory(File baseDir, NarArtifact artifact) throws MojoExecutionException, MojoFailureException { + return baseDir; + } + + public File getNoArchDirectory(File baseDir, MavenProject project) throws MojoExecutionException, MojoFailureException { + return baseDir; + } + + /* + * (non-Javadoc) + * + * @see com.github.maven_nar.NarLayout#getIncludeDirectory(java.io.File) + */ + public final List getIncludeDirectories(File baseDir, NarArtifact artifact) { + ArrayList includes = new ArrayList(); + includes.add(new File(baseDir, fileLayout.getIncludeDirectory())); + return includes; + } + + public final File getIncludeDirectory(File baseDir, MavenProject project) { + return new File(baseDir, fileLayout.getIncludeDirectory()); + } + + /* + * (non-Javadoc) + * + * @see com.github.maven_nar.NarLayout#getLibDir(java.io.File, + * com.github.maven_nar.AOL, String type) + */ + public final File getLibDirectory(File baseDir, NarArtifact artifact, String aol, String type) throws MojoFailureException { + if (type.equals(Library.EXECUTABLE)) { + throw new MojoFailureException("INTERNAL ERROR, Replace call to getLibDirectory with getBinDirectory"); + } + + File dir = new File(baseDir, fileLayout.getLibDirectory(aol, type)); + return dir; + } + + /* + * (non-Javadoc) + * + * @see com.github.maven_nar.NarLayout#getLibDir(java.io.File, + * com.github.maven_nar.AOL, String type) + */ + public final File getLibDirectory(File baseDir, MavenProject project, String aol, String type) throws MojoFailureException { + if (type.equals(Library.EXECUTABLE)) { + throw new MojoFailureException("INTERNAL ERROR, Replace call to getLibDirectory with getBinDirectory"); + } + + File dir = new File(baseDir, fileLayout.getLibDirectory(aol, type)); + return dir; + } + + /* + * (non-Javadoc) + * + * @see com.github.maven_nar.NarLayout#getBinDirectory(java.io.File, + * java.lang.String) + */ + public final File getBinDirectory(File baseDir, NarArtifact artifact, String aol) { + File dir = new File(baseDir, fileLayout.getBinDirectory(aol)); + return dir; + } + + /* + * (non-Javadoc) + * + * @see com.github.maven_nar.NarLayout#getBinDirectory(java.io.File, + * java.lang.String) + */ + public final File getBinDirectory(File baseDir, MavenProject project, String aol) { + File dir = new File(baseDir, fileLayout.getBinDirectory(aol)); + return dir; + } + + /* + * (non-Javadoc) + * + * @see com.github.maven_nar.NarLayout#attachNars(java.io.File, + * org.apache.maven.project.MavenProjectHelper, + * org.apache.maven.project.MavenProject, com.github.maven_nar.NarInfo) + */ + /* + * public final void prepareNarInfo( File baseDir, MavenProject project, + * NarInfo narInfo, AbstractNarMojo mojo ) throws MojoExecutionException { + * if ( getIncludeDirectory( baseDir, project ).exists() ) { narInfo.setNar( + * null, "noarch", project.getGroupId() + ":" + project.getArtifactId() + + * ":" + NarConstants.NAR_TYPE + ":" + "noarch" ); } + * + * String[] binAOL = new File( baseDir, "bin" ).list(); for ( int i = 0; ( + * binAOL != null ) && ( i < binAOL.length ); i++ ) {// TODO: chose not to + * apply new file naming for outfile in case of backwards compatability, may + * need to reconsider narInfo.setNar( null, Library.EXECUTABLE, + * project.getGroupId() + ":" + project.getArtifactId() + ":" + + * NarConstants.NAR_TYPE + ":" + "${aol}" + "-" + Library.EXECUTABLE ); + * narInfo.setBinding( new AOL( binAOL[i] ), Library.EXECUTABLE ); + * narInfo.setBinding( null, Library.EXECUTABLE ); } + * + * File libDir = new File( baseDir, "lib" ); String[] libAOL = + * libDir.list(); for ( int i = 0; ( libAOL != null ) && ( i < libAOL.length + * ); i++ ) { String bindingType = null; String[] libType = new File( + * libDir, libAOL[i] ).list(); for ( int j = 0; ( libType != null ) && ( j < + * libType.length ); j++ ) { narInfo.setNar( null, libType[j], + * project.getGroupId() + ":" + project.getArtifactId() + ":" + + * NarConstants.NAR_TYPE + ":" + "${aol}" + "-" + libType[j] ); + * + * // set if not set or override if SHARED if ( ( bindingType == null ) || + * libType[j].equals( Library.SHARED ) ) { bindingType = libType[j]; } } + * + * AOL aol = new AOL( libAOL[i] ); if ( narInfo.getBinding( aol, null ) == + * null ) { narInfo.setBinding( aol, bindingType != null ? bindingType : + * Library.NONE ); } if ( narInfo.getBinding( null, null ) == null ) { + * narInfo.setBinding( null, bindingType != null ? bindingType : + * Library.NONE ); } } } + * + * public File getNarUnpackDirectory(File baseUnpackDirectory, + * AttachedNarArtifact artifact ) { return baseUnpackDirectory; } + */ } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarLayout21.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarLayout21.java index 7f6aef2..f8370df 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarLayout21.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarLayout21.java @@ -32,214 +32,180 @@ /** * Layout which expands a nar file into: - * + * *
  * nar/noarch/include
  * nar/aol/-/bin
  * nar/aol/-/lib
  * 
- * + * * This loayout has a one-to-one relation with the aol-type version of the nar. - * + * * @author Mark Donszelmann (Mark.Donszelmann@gmail.com) */ -public class NarLayout21 - extends AbstractNarLayout -{ - private NarFileLayout fileLayout; - - public NarLayout21( Log log ) - { - super( log ); - this.fileLayout = new NarFileLayout10(); - } - - public File getNoArchDirectory( File baseDir, NarArtifact artifact ) - { - return new File( baseDir, artifact.getArtifactId() + "-" + artifact.getBaseVersion() + "-" + NarConstants.NAR_NO_ARCH ); - } - - public File getNoArchDirectory( File baseDir, MavenProject project ) - { - return new File( baseDir, project.getArtifactId() + "-" + project.getVersion() + "-" + NarConstants.NAR_NO_ARCH ); - } - - private File getAolDirectory( File baseDir, NarArtifact artifact, String aol, String type ) - { - return new File( baseDir, artifact.getArtifactId() + "-" + artifact.getBaseVersion() + "-" + aol + "-" + type ); - } - - private File getAolDirectory( File baseDir, MavenProject project, String aol, String type ) - { - return new File( baseDir, project.getArtifactId() + "-" + project.getVersion() + "-" + aol + "-" + type ); - } - - /* - * (non-Javadoc) - * @see com.github.maven_nar.NarLayout#getIncludeDirectory(java.io.File) - */ - public final List getIncludeDirectories( File baseDir, NarArtifact artifact ) - { - ArrayList includes = new ArrayList(); - includes.add( new File( getNoArchDirectory( baseDir, artifact ), fileLayout.getIncludeDirectory() ) ); - return includes; - } - - /* - * (non-Javadoc) - * @see com.github.maven_nar.NarLayout#getIncludeDirectory(java.io.File) - */ - public final File getIncludeDirectory( File baseDir, MavenProject project ) - { - return new File( getNoArchDirectory( baseDir, project ), fileLayout.getIncludeDirectory() ); - } - - /* - * (non-Javadoc) - * @see com.github.maven_nar.NarLayout#getLibDir(java.io.File, com.github.maven_nar.AOL, - * java.lang.String) - */ - public final File getLibDirectory( File baseDir, NarArtifact artifact, String aol, String type ) - throws MojoExecutionException - { - if ( type.equals( Library.EXECUTABLE ) ) - { - throw new MojoExecutionException( - "NAR: for type EXECUTABLE call getBinDirectory instead of getLibDirectory" ); - } - - File dir = getAolDirectory( baseDir, artifact, aol, type ); - dir = new File( dir, fileLayout.getLibDirectory( aol, type ) ); - return dir; - } - - /* - * (non-Javadoc) - * @see com.github.maven_nar.NarLayout#getLibDir(java.io.File, com.github.maven_nar.AOL, - * java.lang.String) - */ - public final File getLibDirectory( File baseDir, MavenProject project, String aol, String type ) - throws MojoExecutionException - { - if ( type.equals( Library.EXECUTABLE ) ) - { - throw new MojoExecutionException( - "NAR: for type EXECUTABLE call getBinDirectory instead of getLibDirectory" ); - } - - File dir = getAolDirectory( baseDir, project, aol, type ); - dir = new File( dir, fileLayout.getLibDirectory( aol, type ) ); - return dir; - } - - /* - * (non-Javadoc) - * @see com.github.maven_nar.NarLayout#getLibDir(java.io.File, com.github.maven_nar.AOL, - * java.lang.String) - */ - public final File getBinDirectory( File baseDir, NarArtifact artifact, String aol ) - { - File dir = getAolDirectory( baseDir, artifact, aol, Library.EXECUTABLE ); - dir = new File( dir, fileLayout.getBinDirectory( aol ) ); - return dir; - } - - /* - * (non-Javadoc) - * @see com.github.maven_nar.NarLayout#getLibDir(java.io.File, com.github.maven_nar.AOL, - * java.lang.String) - */ - public final File getBinDirectory( File baseDir, MavenProject project, String aol ) - { - File dir = getAolDirectory( baseDir, project, aol, Library.EXECUTABLE ); - dir = new File( dir, fileLayout.getBinDirectory( aol ) ); - return dir; - } - - /* - * (non-Javadoc) - * @see com.github.maven_nar.NarLayout#attachNars(java.io.File, org.apache.maven.project.MavenProjectHelper, - * org.apache.maven.project.MavenProject, com.github.maven_nar.NarInfo) - */ - /* - public final void prepareNarInfo( File baseDir, MavenProject project, NarInfo narInfo, AbstractNarMojo mojo ) - throws MojoExecutionException - { - if ( getNoArchDirectory( baseDir, project ).exists() ) - { - narInfo.setNar( null, NarConstants.NAR_NO_ARCH, project.getGroupId() + ":" + project.getArtifactId() + ":" - + NarConstants.NAR_TYPE + ":" + NarConstants.NAR_NO_ARCH ); - } - - String artifactIdVersion = project.getArtifactId() + "-" + project.getVersion(); - // list all directories in basedir, scan them for classifiers - String[] subDirs = baseDir.list(); - ArrayList classifiers = new ArrayList(); - for ( int i = 0; ( subDirs != null ) && ( i < subDirs.length ); i++ ) - { - // skip entries not belonging to this project - if ( !subDirs[i].startsWith( artifactIdVersion ) ) - continue; - - String classifier = subDirs[i].substring( artifactIdVersion.length() + 1 ); - - // skip noarch here - if ( classifier.equals( NarConstants.NAR_NO_ARCH ) ) - continue; - - classifiers.add(classifier); - } - - if( !classifiers.isEmpty() ){ - - for(String classifier : classifiers ){ - int lastDash = classifier.lastIndexOf( '-' ); - String type = classifier.substring( lastDash + 1 ); - AOL aol = new AOL( classifier.substring( 0, lastDash ) ); - - if ( ( narInfo.getOutput( aol, null ) == null ) ) - { - narInfo.setOutput( aol, mojo.getOutput(! aol.getOS().contains( OS.WINDOWS ) && ! type.equals( Library.EXECUTABLE ) ) ); - } - - // We prefer shared to jni/executable/static/none, - if ( type.equals( Library.SHARED ) ) // overwrite whatever we had - { - narInfo.setBinding( aol, type ); - narInfo.setBinding( null, type ); - } - else - { - // if the binding is already set, then don't write it for jni/executable/static/none. - if ( ( narInfo.getBinding( aol, null ) == null ) ) - { - narInfo.setBinding( aol, type ); - } - if ( ( narInfo.getBinding( null, null ) == null ) ) - { - narInfo.setBinding( null, type ); - } - } - - narInfo.setNar( null, type, project.getGroupId() + ":" + project.getArtifactId() + ":" - + NarConstants.NAR_TYPE + ":" + "${aol}" + "-" + type ); - - } - - // setting this first stops the per type config because getOutput check for aol defaults to this generic one... - if ( mojo!= null && ( narInfo.getOutput( null, null ) == null ) ) - { - narInfo.setOutput( null, mojo.getOutput(true) ); - } - } - } - - public File getNarUnpackDirectory(File baseUnpackDirectory, AttachedNarArtifact artifact) - { - File dir = new File( - baseUnpackDirectory, - artifact.getArtifactId()+"-"+artifact.getBaseVersion()+"-"+artifact.getClassifier() ); - return dir; - } - */ +public class NarLayout21 extends AbstractNarLayout { + private NarFileLayout fileLayout; + + public NarLayout21(Log log) { + super(log); + this.fileLayout = new NarFileLayout10(); + } + + public File getNoArchDirectory(File baseDir, NarArtifact artifact) { + return new File(baseDir, artifact.getArtifactId() + "-" + artifact.getBaseVersion() + "-" + NarConstants.NAR_NO_ARCH); + } + + public File getNoArchDirectory(File baseDir, MavenProject project) { + return new File(baseDir, project.getArtifactId() + "-" + project.getVersion() + "-" + NarConstants.NAR_NO_ARCH); + } + + private File getAolDirectory(File baseDir, NarArtifact artifact, String aol, String type) { + return new File(baseDir, artifact.getArtifactId() + "-" + artifact.getBaseVersion() + "-" + aol + "-" + type); + } + + private File getAolDirectory(File baseDir, MavenProject project, String aol, String type) { + return new File(baseDir, project.getArtifactId() + "-" + project.getVersion() + "-" + aol + "-" + type); + } + + /* + * (non-Javadoc) + * + * @see com.github.maven_nar.NarLayout#getIncludeDirectory(java.io.File) + */ + public final List getIncludeDirectories(File baseDir, NarArtifact artifact) { + ArrayList includes = new ArrayList(); + includes.add(new File(getNoArchDirectory(baseDir, artifact), fileLayout.getIncludeDirectory())); + return includes; + } + + /* + * (non-Javadoc) + * + * @see com.github.maven_nar.NarLayout#getIncludeDirectory(java.io.File) + */ + public final File getIncludeDirectory(File baseDir, MavenProject project) { + return new File(getNoArchDirectory(baseDir, project), fileLayout.getIncludeDirectory()); + } + + /* + * (non-Javadoc) + * + * @see com.github.maven_nar.NarLayout#getLibDir(java.io.File, + * com.github.maven_nar.AOL, java.lang.String) + */ + public final File getLibDirectory(File baseDir, NarArtifact artifact, String aol, String type) throws MojoExecutionException { + if (type.equals(Library.EXECUTABLE)) { + throw new MojoExecutionException("NAR: for type EXECUTABLE call getBinDirectory instead of getLibDirectory"); + } + + File dir = getAolDirectory(baseDir, artifact, aol, type); + dir = new File(dir, fileLayout.getLibDirectory(aol, type)); + return dir; + } + + /* + * (non-Javadoc) + * + * @see com.github.maven_nar.NarLayout#getLibDir(java.io.File, + * com.github.maven_nar.AOL, java.lang.String) + */ + public final File getLibDirectory(File baseDir, MavenProject project, String aol, String type) throws MojoExecutionException { + if (type.equals(Library.EXECUTABLE)) { + throw new MojoExecutionException("NAR: for type EXECUTABLE call getBinDirectory instead of getLibDirectory"); + } + + File dir = getAolDirectory(baseDir, project, aol, type); + dir = new File(dir, fileLayout.getLibDirectory(aol, type)); + return dir; + } + + /* + * (non-Javadoc) + * + * @see com.github.maven_nar.NarLayout#getLibDir(java.io.File, + * com.github.maven_nar.AOL, java.lang.String) + */ + public final File getBinDirectory(File baseDir, NarArtifact artifact, String aol) { + File dir = getAolDirectory(baseDir, artifact, aol, Library.EXECUTABLE); + dir = new File(dir, fileLayout.getBinDirectory(aol)); + return dir; + } + + /* + * (non-Javadoc) + * + * @see com.github.maven_nar.NarLayout#getLibDir(java.io.File, + * com.github.maven_nar.AOL, java.lang.String) + */ + public final File getBinDirectory(File baseDir, MavenProject project, String aol) { + File dir = getAolDirectory(baseDir, project, aol, Library.EXECUTABLE); + dir = new File(dir, fileLayout.getBinDirectory(aol)); + return dir; + } + + /* + * (non-Javadoc) + * + * @see com.github.maven_nar.NarLayout#attachNars(java.io.File, + * org.apache.maven.project.MavenProjectHelper, + * org.apache.maven.project.MavenProject, com.github.maven_nar.NarInfo) + */ + /* + * public final void prepareNarInfo( File baseDir, MavenProject project, + * NarInfo narInfo, AbstractNarMojo mojo ) throws MojoExecutionException { + * if ( getNoArchDirectory( baseDir, project ).exists() ) { narInfo.setNar( + * null, NarConstants.NAR_NO_ARCH, project.getGroupId() + ":" + + * project.getArtifactId() + ":" + NarConstants.NAR_TYPE + ":" + + * NarConstants.NAR_NO_ARCH ); } + * + * String artifactIdVersion = project.getArtifactId() + "-" + + * project.getVersion(); // list all directories in basedir, scan them for + * classifiers String[] subDirs = baseDir.list(); ArrayList + * classifiers = new ArrayList(); for ( int i = 0; ( subDirs != null + * ) && ( i < subDirs.length ); i++ ) { // skip entries not belonging to + * this project if ( !subDirs[i].startsWith( artifactIdVersion ) ) continue; + * + * String classifier = subDirs[i].substring( artifactIdVersion.length() + 1 + * ); + * + * // skip noarch here if ( classifier.equals( NarConstants.NAR_NO_ARCH ) ) + * continue; + * + * classifiers.add(classifier); } + * + * if( !classifiers.isEmpty() ){ + * + * for(String classifier : classifiers ){ int lastDash = + * classifier.lastIndexOf( '-' ); String type = classifier.substring( + * lastDash + 1 ); AOL aol = new AOL( classifier.substring( 0, lastDash ) ); + * + * if ( ( narInfo.getOutput( aol, null ) == null ) ) { narInfo.setOutput( + * aol, mojo.getOutput(! aol.getOS().contains( OS.WINDOWS ) && ! + * type.equals( Library.EXECUTABLE ) ) ); } + * + * // We prefer shared to jni/executable/static/none, if ( type.equals( + * Library.SHARED ) ) // overwrite whatever we had { narInfo.setBinding( + * aol, type ); narInfo.setBinding( null, type ); } else { // if the binding + * is already set, then don't write it for jni/executable/static/none. if ( + * ( narInfo.getBinding( aol, null ) == null ) ) { narInfo.setBinding( aol, + * type ); } if ( ( narInfo.getBinding( null, null ) == null ) ) { + * narInfo.setBinding( null, type ); } } + * + * narInfo.setNar( null, type, project.getGroupId() + ":" + + * project.getArtifactId() + ":" + NarConstants.NAR_TYPE + ":" + "${aol}" + + * "-" + type ); + * + * } + * + * // setting this first stops the per type config because getOutput check + * for aol defaults to this generic one... if ( mojo!= null && ( + * narInfo.getOutput( null, null ) == null ) ) { narInfo.setOutput( null, + * mojo.getOutput(true) ); } } } + * + * public File getNarUnpackDirectory(File baseUnpackDirectory, + * AttachedNarArtifact artifact) { File dir = new File( baseUnpackDirectory, + * artifact + * .getArtifactId()+"-"+artifact.getBaseVersion()+"-"+artifact.getClassifier + * () ); return dir; } + */ } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarLayout30.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarLayout30.java index ba7c9a5..d040ecf 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarLayout30.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarLayout30.java @@ -31,292 +31,251 @@ import org.apache.maven.project.MavenProject; /** - * Layout which expands a nar file relative to it's location (so in the local repository): - * + * Layout which expands a nar file relative to it's location (so in the local + * repository): + * *
  * nar/extracted/--/
  * 
- * + * * This layout has a one-to-one relation with the aol-type version of the nar. - * + * * @author Mark Donszelmann (Mark.Donszelmann@gmail.com) */ -public class NarLayout30 - extends AbstractNarLayout -{ - private NarFileLayout fileLayout; - - private class NarLockFile { - - private File lockFile; - - private FileOutputStream lockOutputStream; - - private FileLock lock; - - public NarLockFile(File lockFile) { - this.lockFile = lockFile; - while (true) { - try { - lockFile.getParentFile().mkdirs(); - lockOutputStream = new FileOutputStream(lockFile); - lock = lockOutputStream.getChannel().lock(); - break; - } - catch (IOException e) { - getLog().debug( "Locking " + lockFile + " failed: " + e.toString() ); - if (lockOutputStream != null) { - try { - lockOutputStream.close(); - } - catch (IOException e2) { - getLog().debug( e2 ); - } - lockOutputStream = null; - } - try { - Thread.sleep(1000); - } - catch (InterruptedException e2) { - getLog().debug( e2 ); - } - } - } - } - - public void release() { - lockFile.delete(); - try { - lock.release(); - } - catch (IOException e) { - getLog().debug( e ); - } - try { - lockOutputStream.close(); - } - catch (IOException e) { - getLog().debug( e ); - } - } - } - - public NarLayout30( Log log ) - { - super( log ); - this.fileLayout = new NarFileLayout10(); - } - - public File getNoArchDirectory( File baseDir, NarArtifact artifact ) - { - if (artifact.getTargetDirectory() != null) { - // Compile only build so directly use the directory in the sibling module - return new File( artifact.getTargetDirectory(), artifact.getArtifactId() + "-" + artifact.getBaseVersion() + "-" + NarConstants.NAR_NO_ARCH ); - } - else { - // Use the extracted directory relative to the artifact - return new File( artifact.getFile().getParentFile(), "nar" + File.separator + "extracted" + File.separator + artifact.getArtifactId() + "-" + artifact.getBaseVersion() + "-" + NarConstants.NAR_NO_ARCH ); - } - } - - public File getNoArchDirectory( File baseDir, MavenProject project ) - { - return new File( baseDir, project.getArtifactId() + "-" + project.getVersion() + "-" + NarConstants.NAR_NO_ARCH ); - } - - private File getAolDirectory( File baseDir, NarArtifact artifact, String aol, String type ) - { - if (artifact.getTargetDirectory() != null) { - // Compile only build so directly use the directory in the sibling module - return new File( artifact.getTargetDirectory(), artifact.getArtifactId() + "-" + artifact.getBaseVersion() + "-" + aol + "-" + type ); - } - else { - // Use the extracted directory relative to the artifact - return new File( artifact.getFile().getParentFile(), "nar" + File.separator + "extracted" + File.separator + artifact.getArtifactId() + "-" + artifact.getBaseVersion() + "-" + aol + "-" + type ); - } - } - - private File getAolDirectory( File baseDir, MavenProject project, String aol, String type ) - { - return new File( baseDir, project.getArtifactId() + "-" + project.getVersion() + "-" + aol + "-" + type ); - } - - /* - * (non-Javadoc) - * @see com.github.maven_nar.NarLayout#getIncludeDirectory(java.io.File) - */ - public final List getIncludeDirectories( File baseDir, NarArtifact artifact ) - { - ArrayList includes = new ArrayList(); - includes.add( new File( getNoArchDirectory( baseDir, artifact ), fileLayout.getIncludeDirectory() ) ); - return includes; - } - - /* - * (non-Javadoc) - * @see com.github.maven_nar.NarLayout#getIncludeDirectory(java.io.File) - */ - public final File getIncludeDirectory( File baseDir, MavenProject project ) - { - return new File( getNoArchDirectory( baseDir, project ), fileLayout.getIncludeDirectory() ); - } - - /* - * (non-Javadoc) - * @see com.github.maven_nar.NarLayout#getLibDir(java.io.File, com.github.maven_nar.AOL, - * java.lang.String) - */ - public final File getLibDirectory( File baseDir, NarArtifact artifact, String aol, String type ) - throws MojoExecutionException - { - if ( type.equals( Library.EXECUTABLE ) ) - { - throw new MojoExecutionException( - "NAR: for type EXECUTABLE call getBinDirectory instead of getLibDirectory" ); - } - - File dir = getAolDirectory( baseDir, artifact, aol, type ); - dir = new File( dir, fileLayout.getLibDirectory( aol, type ) ); - return dir; - } - - /* - * (non-Javadoc) - * @see com.github.maven_nar.NarLayout#getLibDir(java.io.File, com.github.maven_nar.AOL, - * java.lang.String) - */ - public final File getLibDirectory( File baseDir, MavenProject project, String aol, String type ) - throws MojoExecutionException - { - if ( type.equals( Library.EXECUTABLE ) ) - { - throw new MojoExecutionException( - "NAR: for type EXECUTABLE call getBinDirectory instead of getLibDirectory" ); - } - - File dir = getAolDirectory( baseDir, project, aol, type ); - dir = new File( dir, fileLayout.getLibDirectory( aol, type ) ); - return dir; - } - - /* - * (non-Javadoc) - * @see com.github.maven_nar.NarLayout#getLibDir(java.io.File, com.github.maven_nar.AOL, - * java.lang.String) - */ - public final File getBinDirectory( File baseDir, NarArtifact artifact, String aol ) - { - File dir = getAolDirectory( baseDir, artifact, aol, Library.EXECUTABLE ); - dir = new File( dir, fileLayout.getBinDirectory( aol ) ); - return dir; - } - - /* - * (non-Javadoc) - * @see com.github.maven_nar.NarLayout#getLibDir(java.io.File, com.github.maven_nar.AOL, - * java.lang.String) - */ - public final File getBinDirectory( File baseDir, MavenProject project, String aol ) - { - File dir = getAolDirectory( baseDir, project, aol, Library.EXECUTABLE ); - dir = new File( dir, fileLayout.getBinDirectory( aol ) ); - return dir; - } - - /* - * (non-Javadoc) - * @see com.github.maven_nar.NarLayout#attachNars(java.io.File, org.apache.maven.project.MavenProjectHelper, - * org.apache.maven.project.MavenProject, com.github.maven_nar.NarInfo) - */ - /* - public final void prepareNarInfo( File baseDir, MavenProject project, NarInfo narInfo, AbstractNarMojo mojo ) - throws MojoExecutionException - { - if ( getNoArchDirectory( baseDir, project ).exists() ) - { - narInfo.setNar( null, NarConstants.NAR_NO_ARCH, project.getGroupId() + ":" + project.getArtifactId() + ":" - + NarConstants.NAR_TYPE + ":" + NarConstants.NAR_NO_ARCH ); - } - - String artifactIdVersion = project.getArtifactId() + "-" + project.getVersion(); - // list all directories in basedir, scan them for classifiers - String[] subDirs = baseDir.list(); - ArrayList classifiers = new ArrayList(); - for ( int i = 0; ( subDirs != null ) && ( i < subDirs.length ); i++ ) - { - // skip entries not belonging to this project - if ( !subDirs[i].startsWith( artifactIdVersion ) ) - continue; - - String classifier = subDirs[i].substring( artifactIdVersion.length() + 1 ); - if ( classifier.startsWith("SNAPSHOT-") ) - continue; - - // skip noarch here - if ( classifier.equals( NarConstants.NAR_NO_ARCH ) ) - continue; - - classifiers.add(classifier); - } - - if( !classifiers.isEmpty() ){ - - for(String classifier : classifiers ){ - int lastDash = classifier.lastIndexOf( '-' ); - String type = classifier.substring( lastDash + 1 ); - AOL aol = new AOL( classifier.substring( 0, lastDash ) ); - - if ( ( narInfo.getOutput( aol, null ) == null ) ) - { - narInfo.setOutput( aol, mojo.getOutput(! aol.getOS().contains( OS.WINDOWS ) && ! type.equals( Library.EXECUTABLE ) ) ); - } - - // We prefer shared to jni/executable/static/none, - if ( type.equals( Library.SHARED ) ) // overwrite whatever we had - { - narInfo.setBinding( aol, type ); - narInfo.setBinding( null, type ); - } - else - { - // if the binding is already set, then don't write it for jni/executable/static/none. - if ( ( narInfo.getBinding( aol, null ) == null ) ) - { - narInfo.setBinding( aol, type ); - } - if ( ( narInfo.getBinding( null, null ) == null ) ) - { - narInfo.setBinding( null, type ); - } - } - - narInfo.setNar( null, type, project.getGroupId() + ":" + project.getArtifactId() + ":" - + NarConstants.NAR_TYPE + ":" + "${aol}" + "-" + type ); - - } - - // setting this first stops the per type config because getOutput check for aol defaults to this generic one... - if ( mojo!= null && ( narInfo.getOutput( null, null ) == null ) ) - { - narInfo.setOutput( null, mojo.getOutput(true) ); - } - } - } - - public File getNarUnpackDirectory(File baseUnpackDirectory, AttachedNarArtifact artifact) - { - File dir; - if (artifact.getTargetDirectory() != null) { - dir = new File( - artifact.getTargetDirectory(), - artifact.getArtifactId()+"-"+artifact.getBaseVersion()+"-"+artifact.getClassifier() ); - } - else { - dir = new File( - artifact.getFile().getParentFile(), - "nar" + File.separator + "extracted" + File.separator + artifact.getArtifactId()+"-"+artifact.getBaseVersion()+"-"+artifact.getClassifier() ); - } - return dir; - } - */ +public class NarLayout30 extends AbstractNarLayout { + private NarFileLayout fileLayout; + + private class NarLockFile { + + private File lockFile; + + private FileOutputStream lockOutputStream; + + private FileLock lock; + + public NarLockFile(File lockFile) { + this.lockFile = lockFile; + while (true) { + try { + lockFile.getParentFile().mkdirs(); + lockOutputStream = new FileOutputStream(lockFile); + lock = lockOutputStream.getChannel().lock(); + break; + } catch (IOException e) { + getLog().debug("Locking " + lockFile + " failed: " + e.toString()); + if (lockOutputStream != null) { + try { + lockOutputStream.close(); + } catch (IOException e2) { + getLog().debug(e2); + } + lockOutputStream = null; + } + try { + Thread.sleep(1000); + } catch (InterruptedException e2) { + getLog().debug(e2); + } + } + } + } + + public void release() { + lockFile.delete(); + try { + lock.release(); + } catch (IOException e) { + getLog().debug(e); + } + try { + lockOutputStream.close(); + } catch (IOException e) { + getLog().debug(e); + } + } + } + + public NarLayout30(Log log) { + super(log); + this.fileLayout = new NarFileLayout10(); + } + + public File getNoArchDirectory(File baseDir, NarArtifact artifact) { + if (artifact.getTargetDirectory() != null) { + // Compile only build so directly use the directory in the sibling + // module + return new File(artifact.getTargetDirectory(), artifact.getArtifactId() + "-" + artifact.getBaseVersion() + "-" + NarConstants.NAR_NO_ARCH); + } else { + // Use the extracted directory relative to the artifact + return new File(artifact.getFile().getParentFile(), "nar" + File.separator + "extracted" + File.separator + artifact.getArtifactId() + "-" + + artifact.getBaseVersion() + "-" + NarConstants.NAR_NO_ARCH); + } + } + + public File getNoArchDirectory(File baseDir, MavenProject project) { + return new File(baseDir, project.getArtifactId() + "-" + project.getVersion() + "-" + NarConstants.NAR_NO_ARCH); + } + + private File getAolDirectory(File baseDir, NarArtifact artifact, String aol, String type) { + if (artifact.getTargetDirectory() != null) { + // Compile only build so directly use the directory in the sibling + // module + return new File(artifact.getTargetDirectory(), artifact.getArtifactId() + "-" + artifact.getBaseVersion() + "-" + aol + "-" + type); + } else { + // Use the extracted directory relative to the artifact + return new File(artifact.getFile().getParentFile(), "nar" + File.separator + "extracted" + File.separator + artifact.getArtifactId() + "-" + + artifact.getBaseVersion() + "-" + aol + "-" + type); + } + } + + private File getAolDirectory(File baseDir, MavenProject project, String aol, String type) { + return new File(baseDir, project.getArtifactId() + "-" + project.getVersion() + "-" + aol + "-" + type); + } + + /* + * (non-Javadoc) + * + * @see com.github.maven_nar.NarLayout#getIncludeDirectory(java.io.File) + */ + public final List getIncludeDirectories(File baseDir, NarArtifact artifact) { + ArrayList includes = new ArrayList(); + includes.add(new File(getNoArchDirectory(baseDir, artifact), fileLayout.getIncludeDirectory())); + return includes; + } + + /* + * (non-Javadoc) + * + * @see com.github.maven_nar.NarLayout#getIncludeDirectory(java.io.File) + */ + public final File getIncludeDirectory(File baseDir, MavenProject project) { + return new File(getNoArchDirectory(baseDir, project), fileLayout.getIncludeDirectory()); + } + + /* + * (non-Javadoc) + * + * @see com.github.maven_nar.NarLayout#getLibDir(java.io.File, + * com.github.maven_nar.AOL, java.lang.String) + */ + public final File getLibDirectory(File baseDir, NarArtifact artifact, String aol, String type) throws MojoExecutionException { + if (type.equals(Library.EXECUTABLE)) { + throw new MojoExecutionException("NAR: for type EXECUTABLE call getBinDirectory instead of getLibDirectory"); + } + + File dir = getAolDirectory(baseDir, artifact, aol, type); + dir = new File(dir, fileLayout.getLibDirectory(aol, type)); + return dir; + } + + /* + * (non-Javadoc) + * + * @see com.github.maven_nar.NarLayout#getLibDir(java.io.File, + * com.github.maven_nar.AOL, java.lang.String) + */ + public final File getLibDirectory(File baseDir, MavenProject project, String aol, String type) throws MojoExecutionException { + if (type.equals(Library.EXECUTABLE)) { + throw new MojoExecutionException("NAR: for type EXECUTABLE call getBinDirectory instead of getLibDirectory"); + } + + File dir = getAolDirectory(baseDir, project, aol, type); + dir = new File(dir, fileLayout.getLibDirectory(aol, type)); + return dir; + } + + /* + * (non-Javadoc) + * + * @see com.github.maven_nar.NarLayout#getLibDir(java.io.File, + * com.github.maven_nar.AOL, java.lang.String) + */ + public final File getBinDirectory(File baseDir, NarArtifact artifact, String aol) { + File dir = getAolDirectory(baseDir, artifact, aol, Library.EXECUTABLE); + dir = new File(dir, fileLayout.getBinDirectory(aol)); + return dir; + } + + /* + * (non-Javadoc) + * + * @see com.github.maven_nar.NarLayout#getLibDir(java.io.File, + * com.github.maven_nar.AOL, java.lang.String) + */ + public final File getBinDirectory(File baseDir, MavenProject project, String aol) { + File dir = getAolDirectory(baseDir, project, aol, Library.EXECUTABLE); + dir = new File(dir, fileLayout.getBinDirectory(aol)); + return dir; + } + + /* + * (non-Javadoc) + * + * @see com.github.maven_nar.NarLayout#attachNars(java.io.File, + * org.apache.maven.project.MavenProjectHelper, + * org.apache.maven.project.MavenProject, com.github.maven_nar.NarInfo) + */ + /* + * public final void prepareNarInfo( File baseDir, MavenProject project, + * NarInfo narInfo, AbstractNarMojo mojo ) throws MojoExecutionException { + * if ( getNoArchDirectory( baseDir, project ).exists() ) { narInfo.setNar( + * null, NarConstants.NAR_NO_ARCH, project.getGroupId() + ":" + + * project.getArtifactId() + ":" + NarConstants.NAR_TYPE + ":" + + * NarConstants.NAR_NO_ARCH ); } + * + * String artifactIdVersion = project.getArtifactId() + "-" + + * project.getVersion(); // list all directories in basedir, scan them for + * classifiers String[] subDirs = baseDir.list(); ArrayList + * classifiers = new ArrayList(); for ( int i = 0; ( subDirs != null + * ) && ( i < subDirs.length ); i++ ) { // skip entries not belonging to + * this project if ( !subDirs[i].startsWith( artifactIdVersion ) ) continue; + * + * String classifier = subDirs[i].substring( artifactIdVersion.length() + 1 + * ); if ( classifier.startsWith("SNAPSHOT-") ) continue; + * + * // skip noarch here if ( classifier.equals( NarConstants.NAR_NO_ARCH ) ) + * continue; + * + * classifiers.add(classifier); } + * + * if( !classifiers.isEmpty() ){ + * + * for(String classifier : classifiers ){ int lastDash = + * classifier.lastIndexOf( '-' ); String type = classifier.substring( + * lastDash + 1 ); AOL aol = new AOL( classifier.substring( 0, lastDash ) ); + * + * if ( ( narInfo.getOutput( aol, null ) == null ) ) { narInfo.setOutput( + * aol, mojo.getOutput(! aol.getOS().contains( OS.WINDOWS ) && ! + * type.equals( Library.EXECUTABLE ) ) ); } + * + * // We prefer shared to jni/executable/static/none, if ( type.equals( + * Library.SHARED ) ) // overwrite whatever we had { narInfo.setBinding( + * aol, type ); narInfo.setBinding( null, type ); } else { // if the binding + * is already set, then don't write it for jni/executable/static/none. if ( + * ( narInfo.getBinding( aol, null ) == null ) ) { narInfo.setBinding( aol, + * type ); } if ( ( narInfo.getBinding( null, null ) == null ) ) { + * narInfo.setBinding( null, type ); } } + * + * narInfo.setNar( null, type, project.getGroupId() + ":" + + * project.getArtifactId() + ":" + NarConstants.NAR_TYPE + ":" + "${aol}" + + * "-" + type ); + * + * } + * + * // setting this first stops the per type config because getOutput check + * for aol defaults to this generic one... if ( mojo!= null && ( + * narInfo.getOutput( null, null ) == null ) ) { narInfo.setOutput( null, + * mojo.getOutput(true) ); } } } + * + * public File getNarUnpackDirectory(File baseUnpackDirectory, + * AttachedNarArtifact artifact) { File dir; if + * (artifact.getTargetDirectory() != null) { dir = new File( + * artifact.getTargetDirectory(), + * artifact.getArtifactId()+"-"+artifact.getBaseVersion + * ()+"-"+artifact.getClassifier() ); } else { dir = new File( + * artifact.getFile().getParentFile(), "nar" + File.separator + "extracted" + * + File.separator + + * artifact.getArtifactId()+"-"+artifact.getBaseVersion()+ + * "-"+artifact.getClassifier() ); } return dir; } + */ } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarProperties.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarProperties.java index 6cf6857..a109d19 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarProperties.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarProperties.java @@ -34,67 +34,54 @@ import org.codehaus.plexus.util.PropertyUtils; public class NarProperties { - + private final static String AOL_PROPERTIES = "aol.properties"; private final static String CUSTOM_AOL_PROPERTY_KEY = "nar.aolProperties"; private Properties properties; - - public NarProperties(MavenProject project, Class classNearResource) throws MojoFailureException - { + + public NarProperties(MavenProject project, Class classNearResource) throws MojoFailureException { Properties defaults = null; - final InputStream stream = classNearResource.getResourceAsStream( AOL_PROPERTIES ); - if (stream != null) - { - defaults = PropertyUtils.loadProperties( stream ); - } - if ( defaults == null ) - { - throw new MojoFailureException( "NAR: Could not load default properties file: '"+AOL_PROPERTIES+"'." ); - } - properties = new Properties(defaults); - FileInputStream fis = null; - String customPropertyLocation = null; - try - { - if (project != null) { - customPropertyLocation = project.getProperties().getProperty(CUSTOM_AOL_PROPERTY_KEY); - if (customPropertyLocation == null) { - // Try and read from the system property in case it's specified there - customPropertyLocation = System.getProperties().getProperty(CUSTOM_AOL_PROPERTY_KEY); - } - fis = new FileInputStream(customPropertyLocation != null ? - customPropertyLocation : project.getBasedir()+File.separator+AOL_PROPERTIES); - properties.load( fis ); - } - } - catch (FileNotFoundException e) - { + final InputStream stream = classNearResource.getResourceAsStream(AOL_PROPERTIES); + if (stream != null) { + defaults = PropertyUtils.loadProperties(stream); + } + if (defaults == null) { + throw new MojoFailureException("NAR: Could not load default properties file: '" + AOL_PROPERTIES + "'."); + } + properties = new Properties(defaults); + FileInputStream fis = null; + String customPropertyLocation = null; + try { + if (project != null) { + customPropertyLocation = project.getProperties().getProperty(CUSTOM_AOL_PROPERTY_KEY); + if (customPropertyLocation == null) { + // Try and read from the system property in case it's + // specified there + customPropertyLocation = System.getProperties().getProperty(CUSTOM_AOL_PROPERTY_KEY); + } + fis = new FileInputStream(customPropertyLocation != null ? customPropertyLocation : project.getBasedir() + File.separator + AOL_PROPERTIES); + properties.load(fis); + } + } catch (FileNotFoundException e) { if (customPropertyLocation != null) { - // We tried loading from a custom location - so throw the exception - throw new MojoFailureException( "NAR: Could not load custom properties file: '"+customPropertyLocation+"'." ); + // We tried loading from a custom location - so throw the + // exception + throw new MojoFailureException("NAR: Could not load custom properties file: '" + customPropertyLocation + "'."); } - } - catch (IOException e) - { + } catch (IOException e) { // ignore (FIXME) + } finally { + try { + if (fis != null) { + fis.close(); + } + } catch (IOException e) { + // ignore + } } - finally - { - try - { - if ( fis != null ) - { - fis.close(); - } - } - catch ( IOException e ) - { - // ignore - } - } } - + public String getProperty(String key) { return properties.getProperty(key); } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarTestCompileMojo.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarTestCompileMojo.java index fbcee58..56a8c52 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarTestCompileMojo.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarTestCompileMojo.java @@ -30,29 +30,27 @@ /** * Compiles native test source files. - * + * * @goal nar-testCompile * @phase test-compile * @requiresDependencyResolution test * @threadSafe * @author Mark Donszelmann */ -public class NarTestCompileMojo - extends AbstractCompileMojo -{ - /** - * Skip running of NAR integration test plugins. - * - * @parameter property="skipNar" default-value="false" - */ - protected boolean skipNar; +public class NarTestCompileMojo extends AbstractCompileMojo { + /** + * Skip running of NAR integration test plugins. + * + * @parameter property="skipNar" default-value="false" + */ + protected boolean skipNar; - protected List getArtifacts() { - final Set artifacts = getMavenProject().getArtifacts(); - List returnArtifact = new ArrayList(); - for(Artifact a : artifacts) { - returnArtifact.add(a); - } - return returnArtifact; - } + protected List getArtifacts() { + final Set artifacts = getMavenProject().getArtifacts(); + List returnArtifact = new ArrayList(); + for (Artifact a : artifacts) { + returnArtifact.add(a); + } + return returnArtifact; + } } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarUtil.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarUtil.java index 3868fd6..8eeecfb 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarUtil.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/NarUtil.java @@ -46,660 +46,511 @@ /** * @author Mark Donszelmann */ -public final class NarUtil -{ - /** - * A class that splits a white-space, comma-separated list into a String - * array. - */ - public static final class StringArrayBuilder { - private String[] _value; - public StringArrayBuilder(String value) { - // Split the defines up - StringTokenizer tokens = new StringTokenizer(value, ", "); - Vector vallist = new Vector(); - while (tokens.hasMoreTokens()) { - String val = tokens.nextToken().trim(); - if (val.length() == 0) { - continue; - } - vallist.addElement(val); - } - _value = new String[vallist.size()]; - vallist.copyInto(_value); - } - public String[] getValue() { - return _value; - } - } - - private NarUtil() - { - // never instantiate - } - - public static String getOS( String defaultOs ) - { - String os = defaultOs; - // adjust OS if not given - if ( os == null ) - { - os = System.getProperty( "os.name" ); - String name = os.toLowerCase(); - if ( name.startsWith( "windows" ) ) - { - os = OS.WINDOWS; - } - if ( name.startsWith( "linux" ) ) - { - os = OS.LINUX; - } - if ( name.equals( "mac os x" ) ) - { - os = OS.MACOSX; - } - } - return os; - } - - public static String getArchitecture( String architecture ) - { - if (architecture == null) { - return System.getProperty( "os.arch" ); - } - return architecture; - } - - public static Linker getLinker( Linker linker, final Log log ) - { - Linker link = linker; - if ( link == null ) - { - link = new Linker( log ); - } - return link; - } - - public static String getLinkerName(NarProperties properties, String architecture, String os, Linker linker, final Log log ) - throws MojoFailureException, MojoExecutionException - { - return getLinker( linker, log ).getName( properties, getArchitecture( architecture ) + "." + getOS( os ) + "." ); - } - - public static AOL getAOL(NarProperties properties, String architecture, String os, Linker linker, String aol, String aolSuffix, final Log log ) - throws MojoFailureException, MojoExecutionException - { - // adjust aol - return aol == null ? new AOL( getArchitecture( architecture ), getOS( os ), getLinkerName( properties, architecture, os, - linker, log ), aolSuffix ) - : new AOL( aol, aolSuffix ); - } - - // FIXME, should go to AOL. -/* NOT USED ? - public static String getAOLKey( String architecture, String os, Linker linker ) - throws MojoFailureException, MojoExecutionException - { - // construct AOL key prefix - return getArchitecture( architecture ) + "." + getOS( os ) + "." + getLinkerName( architecture, os, linker ) - + "."; - } -*/ - - public static String getAOLKey( String aol ) - { - return new AOL(aol).getKey(); - } - - public static File getJavaHome( File javaHome, String os ) - { - File home = javaHome; - // adjust JavaHome - if ( home == null ) - { - home = new File( System.getProperty( "java.home" ) ); - if ( home.getName().equals("jre") ) - { - // we want the JDK base directory, not the JRE subfolder - home = home.getParentFile(); - } - } - return home; - } - - public static void makeExecutable( File file, final Log log ) - throws MojoExecutionException, MojoFailureException - { - if ( !file.exists() ) - { - return; - } - - if ( file.isDirectory() ) - { - File[] files = file.listFiles(); - for ( int i = 0; i < files.length; i++ ) - { - makeExecutable( files[i], log ); - } - } - if ( file.isFile() && file.canRead() && file.canWrite() && !file.isHidden() ) - { - // chmod +x file - int result = runCommand( "chmod", new String[] { "+x", file.getPath() }, null, null, log ); - if ( result != 0 ) - { - throw new MojoExecutionException( "Failed to execute 'chmod +x " + file.getPath() + "'" - + " return code: \'" + result + "\'." ); - } - } - } - - public static void runRanlib( File file, final Log log ) - throws MojoExecutionException, MojoFailureException - { - if ( !file.exists() ) - { - return; - } - - if ( file.isDirectory() ) - { - File[] files = file.listFiles(); - for ( int i = 0; i < files.length; i++ ) - { - runRanlib( files[i], log ); - } - } - if ( file.isFile() && file.canWrite() && !file.isHidden() && file.getName().endsWith( ".a" ) ) - { - // ranlib file - int result = runCommand( "ranlib", new String[] { file.getPath() }, null, null, log ); - if ( result != 0 ) - { - throw new MojoExecutionException( "Failed to execute 'ranlib " + file.getPath() + "'" - + " return code: \'" + result + "\'." ); - } - } - } - - static void runInstallNameTool( File[] files, final Log log ) - throws MojoExecutionException, MojoFailureException - { - Set libs = findInstallNameToolCandidates( files, log ); - - for ( Iterator i = libs.iterator(); i.hasNext(); ) - { - File subjectFile = ( File )i.next(); - String subjectName = subjectFile.getName(); - String subjectPath = subjectFile.getPath(); - - int idResult = runCommand( - "install_name_tool", - new String[] { "-id", subjectPath, subjectPath }, - null, null, log ); - - if ( idResult != 0 ) - { - throw new MojoExecutionException( - "Failed to execute 'install_name_tool -id " - + subjectPath - + " " - + subjectPath - + "'" - + " return code: \'" - + idResult - + "\'." ); - } - - for ( Iterator j = libs.iterator(); j.hasNext(); ) - { - File dependentFile = ( File )j.next(); - String dependentPath = dependentFile.getPath(); - - if (dependentPath == subjectPath) continue; - - int changeResult = runCommand( - "install_name_tool", - new String[] { "-change", subjectName, subjectPath, dependentPath }, - null, null, log ); - - if ( changeResult != 0 ) - { - throw new MojoExecutionException( - "Failed to execute 'install_name_tool -change " - + subjectName - + " " - + subjectPath - + " " - + dependentPath - + "'" - + " return code: \'" - + changeResult - + "\'." ); - } - } - } - } - - static Set findInstallNameToolCandidates( File[] files, final Log log ) - throws MojoExecutionException, MojoFailureException - { - HashSet candidates = new HashSet(); - - for (int i = 0; i < files.length; i++) - { - File file = files[i]; - - if ( !file.exists() ) - { - continue; - } - - if ( file.isDirectory() ) - { - candidates.addAll(findInstallNameToolCandidates( file.listFiles(), log )); - } - - String fileName = file.getName(); - if ( file.isFile() && file.canWrite() - && ( fileName.endsWith( ".so" ) || fileName.endsWith( ".dylib" ) || (fileName.endsWith( ".jnilib" )))) - { - candidates.add(file); - } - } - - return candidates; - } - - public static void makeLink( File file, final Log log ) - throws MojoExecutionException, MojoFailureException - { - if ( !file.exists() ) - { - return; - } - - if ( file.isDirectory() ) - { - File[] files = file.listFiles(); - for ( int i = 0; i < files.length; i++ ) - { - makeLink( files[i], log ); - } - // Run ldconfig to create soname links - runCommand( "/sbin/ldconfig", new String[] { "-n", file.getPath() }, null, null, log ); - } - if ( file.isFile() && file.canRead() && file.canWrite() && !file.isHidden() - && file.getName().matches( ".*\\.so(\\.\\d+)+$" ) ) - { - File sofile = - new File( file.getParent(), file.getName().substring( 0, file.getName().indexOf( ".so" ) + 3 ) ); - if ( !sofile.exists() ) - { - // ln -s lib.so.xx lib.so - int result = - runCommand( "ln", new String[] { "-s", file.getName(), sofile.getPath() }, null, null, log ); - if ( result != 0 ) - { - throw new MojoExecutionException( "Failed to execute 'ln -s " + file.getName() + " " - + sofile.getPath() + "'" + " return code: \'" + result + "\'." ); - } - } - } - } - - /** - * Returns the header file name (javah) corresponding to the given class file name - * - * @param filename the absolute file name of the class - * @return the header file name. - */ - public static String getHeaderName( String basename, String filename ) - { - String base = basename.replaceAll( "\\\\", "/" ); - String file = filename.replaceAll( "\\\\", "/" ); - if ( !file.startsWith( base ) ) - { - throw new IllegalArgumentException( "Error " + file + " does not start with " + base ); - } - String header = file.substring( base.length() + 1 ); - header = header.replaceAll( "/", "_" ); - header = header.replaceAll( "\\.class", ".h" ); - return header; - } - - /** - * Replaces target with replacement in string. For jdk 1.4 compatiblity. - * - * @param target - * @param replacement - * @param string - * @return - */ - public static String replace( CharSequence target, CharSequence replacement, String string ) - { - return Pattern.compile( quote( target.toString() )/* - * , Pattern.LITERAL jdk 1.4 - */).matcher( string ).replaceAll( - /* Matcher. jdk 1.4 */quoteReplacement( replacement.toString() ) ); - } - - /* for jdk 1.4 */ - private static String quote( String s ) - { - final String escQ = "\\Q"; - final String escE = "\\E"; - - int slashEIndex = s.indexOf( escE ); - if ( slashEIndex == -1 ) - { - return escQ + s + escE; - } - - StringBuffer sb = new StringBuffer( s.length() * 2 ); - sb.append( escQ ); - slashEIndex = 0; - int current = 0; - while ( ( slashEIndex = s.indexOf( escE, current ) ) != -1 ) - { - sb.append( s.substring( current, slashEIndex ) ); - current = slashEIndex + 2; - sb.append( escE ); - sb.append( "\\" ); - sb.append( escE ); - sb.append( escQ ); - } - sb.append( s.substring( current, s.length() ) ); - sb.append( escE ); - return sb.toString(); - } - - /* for jdk 1.4 */ - private static String quoteReplacement( String s ) - { - if ( ( s.indexOf( '\\' ) == -1 ) && ( s.indexOf( '$' ) == -1 ) ) - { - return s; - } - StringBuffer sb = new StringBuffer(); - for ( int i = 0; i < s.length(); i++ ) - { - char c = s.charAt( i ); - if ( c == '\\' ) - { - sb.append( '\\' ); - sb.append( '\\' ); - } - else if ( c == '$' ) - { - sb.append( '\\' ); - sb.append( '$' ); - } - else - { - sb.append( c ); - } - } - return sb.toString(); - } - - public static final String DEFAULT_EXCLUDES = - "**/*~,**/#*#,**/.#*,**/%*%,**/._*," + "**/CVS,**/CVS/**,**/.cvsignore," + "**/SCCS,**/SCCS/**,**/vssver.scc," - + "**/.svn,**/.svn/**,**/.DS_Store"; - - public static String getEnv( String envKey, String alternateSystemProperty, String defaultValue ) - { - String envValue = null; - try - { - envValue = System.getenv( envKey ); - if ( envValue == null && alternateSystemProperty != null ) - { - envValue = System.getProperty( alternateSystemProperty ); - } - } - catch ( Error e ) - { - // JDK 1.4? - if ( alternateSystemProperty != null ) - { - envValue = System.getProperty( alternateSystemProperty ); - } - } - - if ( envValue == null ) - { - envValue = defaultValue; - } - - return envValue; - } - - public static String addLibraryPathToEnv( String path, Map environment, String os ) - { - String pathName = null; - char separator = ' '; - if ( os.equals( OS.WINDOWS ) ) - { - pathName = "Path"; - separator = ';'; - } - else if ( os.equals( OS.MACOSX ) ) - { - pathName = "DYLD_LIBRARY_PATH"; - separator = ':'; - } - else - { - pathName = "LD_LIBRARY_PATH"; - separator = ':'; - } - - String value = environment != null ? (String) environment.get( pathName ) : null; - if ( value == null ) - { - value = NarUtil.getEnv( pathName, pathName, null ); - } - - String libPath = path; - libPath = libPath.replace( File.pathSeparatorChar, separator ); - if ( value != null ) - { - value += separator + libPath; - } - else - { - value = libPath; - } - if ( environment != null ) - { - environment.put( pathName, value ); - } - return pathName + "=" + value; - } - - public static int runCommand( String cmd, String[] args, File workingDirectory, String[] env, final Log log ) - throws MojoExecutionException, MojoFailureException - { - if ( log.isInfoEnabled() ) - { - final StringBuilder argLine = new StringBuilder(); - if ( args != null ) - { - for ( final String arg : args ) - { - argLine.append( " " + arg ); - } - } - if ( workingDirectory != null ) - { - log.info( "+ cd " + workingDirectory.getAbsolutePath() ); - } - log.info( "+ " + cmd + argLine ); - } - return runCommand( cmd, args, workingDirectory, env, new TextStream() - { - public void println( String text ) - { - log.info( text ); - } - }, new TextStream() - { - public void println( String text ) - { - log.error( text ); - } - - }, new TextStream() - { - public void println( String text ) - { - log.debug( text ); - } - } , log ); - } - - public static int runCommand( String cmd, String[] args, File workingDirectory, String[] env, TextStream out, - TextStream err, TextStream dbg, final Log log ) - throws MojoExecutionException, MojoFailureException - { - return runCommand( cmd, args, workingDirectory, env, out, err, dbg, log, false ); - } - - public static int runCommand( String cmd, String[] args, File workingDirectory, String[] env, TextStream out, - TextStream err, TextStream dbg, final Log log, boolean expectFailure ) - throws MojoExecutionException, MojoFailureException - { - Commandline cmdLine = new Commandline(); - - try - { - dbg.println( "RunCommand: " + cmd ); - cmdLine.setExecutable( cmd ); - if ( args != null ) - { - for ( int i = 0; i < args.length; i++ ) - { - dbg.println( " '" + args[i] + "'" ); - } - cmdLine.addArguments( args ); - } - if ( workingDirectory != null ) - { - dbg.println( "in: " + workingDirectory.getPath() ); - cmdLine.setWorkingDirectory( workingDirectory ); - } - - if ( env != null ) - { - dbg.println( "with Env:" ); - for ( int i = 0; i < env.length; i++ ) - { - String[] nameValue = env[i].split( "=", 2 ); - if ( nameValue.length < 2 ) - { - throw new MojoFailureException( " Misformed env: '" + env[i] + "'" ); - } - dbg.println( " '" + nameValue[0] + "=" + nameValue[1] + "'" ); - cmdLine.addEnvironment( nameValue[0], nameValue[1] ); - } - } - - Process process = cmdLine.execute(); - StreamGobbler errorGobbler = new StreamGobbler( process.getErrorStream(), err ); - StreamGobbler outputGobbler = new StreamGobbler( process.getInputStream(), out ); - - errorGobbler.start(); - outputGobbler.start(); - process.waitFor(); - int exitValue = process.exitValue(); - dbg.println( "ExitValue: " + exitValue ); - final int timeout = 5000; - errorGobbler.join( timeout ); - outputGobbler.join( timeout ); - if ( exitValue != 0 ^ expectFailure ) - { - if ( log == null ) - { - System.err.println(err.toString()); - System.err.println(out.toString()); - System.err.println(dbg.toString()); - } - else - { - log.warn(err.toString()); - log.warn(out.toString()); - log.warn(dbg.toString()); - } - throw new MojoExecutionException( "exit code: " + exitValue ); - } - return exitValue; - } - catch ( MojoExecutionException e ) - { - throw e; - } - catch ( Exception e ) - { - throw new MojoExecutionException( "Could not launch " + cmdLine, e ); - } - } - - private static final class StreamGobbler - extends Thread - { - private InputStream is; - - private TextStream ts; - - private StreamGobbler( InputStream is, TextStream ts ) - { - this.is = is; - this.ts = ts; - } - - public void run() - { - try - { - BufferedReader reader = new BufferedReader( new InputStreamReader( is ) ); - String line = null; - while ( ( line = reader.readLine() ) != null ) - { - ts.println( line ); - } - reader.close(); - } - catch ( IOException e ) - { - // e.printStackTrace() - StackTraceElement[] stackTrace = e.getStackTrace(); - for ( int i = 0; i < stackTrace.length; i++ ) - { - ts.println( stackTrace[i].toString() ); - } - } - } - } - - - /** - * (Darren) this code lifted from mvn help:active-profiles plugin Recurses - * into the project's parent poms to find the active profiles of the - * specified project and all its parents. - * - * @param project - * The project to start with - * @return A list of active profiles - */ - static List collectActiveProfiles(MavenProject project) { - List profiles = project.getActiveProfiles(); - - if (project.hasParent()) { - profiles.addAll(collectActiveProfiles(project.getParent())); - } - - return profiles; - } +public final class NarUtil { + /** + * A class that splits a white-space, comma-separated list into a String + * array. + */ + public static final class StringArrayBuilder { + private String[] _value; + + public StringArrayBuilder(String value) { + // Split the defines up + StringTokenizer tokens = new StringTokenizer(value, ", "); + Vector vallist = new Vector(); + while (tokens.hasMoreTokens()) { + String val = tokens.nextToken().trim(); + if (val.length() == 0) { + continue; + } + vallist.addElement(val); + } + _value = new String[vallist.size()]; + vallist.copyInto(_value); + } + + public String[] getValue() { + return _value; + } + } + + private NarUtil() { + // never instantiate + } + + public static String getOS(String defaultOs) { + String os = defaultOs; + // adjust OS if not given + if (os == null) { + os = System.getProperty("os.name"); + String name = os.toLowerCase(); + if (name.startsWith("windows")) { + os = OS.WINDOWS; + } + if (name.startsWith("linux")) { + os = OS.LINUX; + } + if (name.equals("mac os x")) { + os = OS.MACOSX; + } + } + return os; + } + + public static String getArchitecture(String architecture) { + if (architecture == null) { + return System.getProperty("os.arch"); + } + return architecture; + } + + public static Linker getLinker(Linker linker, final Log log) { + Linker link = linker; + if (link == null) { + link = new Linker(log); + } + return link; + } + + public static String getLinkerName(NarProperties properties, String architecture, String os, Linker linker, final Log log) throws MojoFailureException, + MojoExecutionException { + return getLinker(linker, log).getName(properties, getArchitecture(architecture) + "." + getOS(os) + "."); + } + + public static AOL getAOL(NarProperties properties, String architecture, String os, Linker linker, String aol, String aolSuffix, final Log log) + throws MojoFailureException, MojoExecutionException { + // adjust aol + return aol == null ? new AOL(getArchitecture(architecture), getOS(os), getLinkerName(properties, architecture, os, linker, log), aolSuffix) : new AOL( + aol, aolSuffix); + } + + // FIXME, should go to AOL. + /* + * NOT USED ? public static String getAOLKey( String architecture, String + * os, Linker linker ) throws MojoFailureException, MojoExecutionException { + * // construct AOL key prefix return getArchitecture( architecture ) + "." + * + getOS( os ) + "." + getLinkerName( architecture, os, linker ) + "."; } + */ + + public static String getAOLKey(String aol) { + return new AOL(aol).getKey(); + } + + public static File getJavaHome(File javaHome, String os) { + File home = javaHome; + // adjust JavaHome + if (home == null) { + home = new File(System.getProperty("java.home")); + if (home.getName().equals("jre")) { + // we want the JDK base directory, not the JRE subfolder + home = home.getParentFile(); + } + } + return home; + } + + public static void makeExecutable(File file, final Log log) throws MojoExecutionException, MojoFailureException { + if (!file.exists()) { + return; + } + + if (file.isDirectory()) { + File[] files = file.listFiles(); + for (int i = 0; i < files.length; i++) { + makeExecutable(files[i], log); + } + } + if (file.isFile() && file.canRead() && file.canWrite() && !file.isHidden()) { + // chmod +x file + int result = runCommand("chmod", new String[] { "+x", file.getPath() }, null, null, log); + if (result != 0) { + throw new MojoExecutionException("Failed to execute 'chmod +x " + file.getPath() + "'" + " return code: \'" + result + "\'."); + } + } + } + + public static void runRanlib(File file, final Log log) throws MojoExecutionException, MojoFailureException { + if (!file.exists()) { + return; + } + + if (file.isDirectory()) { + File[] files = file.listFiles(); + for (int i = 0; i < files.length; i++) { + runRanlib(files[i], log); + } + } + if (file.isFile() && file.canWrite() && !file.isHidden() && file.getName().endsWith(".a")) { + // ranlib file + int result = runCommand("ranlib", new String[] { file.getPath() }, null, null, log); + if (result != 0) { + throw new MojoExecutionException("Failed to execute 'ranlib " + file.getPath() + "'" + " return code: \'" + result + "\'."); + } + } + } + + static void runInstallNameTool(File[] files, final Log log) throws MojoExecutionException, MojoFailureException { + Set libs = findInstallNameToolCandidates(files, log); + + for (Iterator i = libs.iterator(); i.hasNext();) { + File subjectFile = (File) i.next(); + String subjectName = subjectFile.getName(); + String subjectPath = subjectFile.getPath(); + + int idResult = runCommand("install_name_tool", new String[] { "-id", subjectPath, subjectPath }, null, null, log); + + if (idResult != 0) { + throw new MojoExecutionException("Failed to execute 'install_name_tool -id " + subjectPath + " " + subjectPath + "'" + " return code: \'" + + idResult + "\'."); + } + + for (Iterator j = libs.iterator(); j.hasNext();) { + File dependentFile = (File) j.next(); + String dependentPath = dependentFile.getPath(); + + if (dependentPath == subjectPath) + continue; + + int changeResult = runCommand("install_name_tool", new String[] { "-change", subjectName, subjectPath, dependentPath }, null, null, log); + + if (changeResult != 0) { + throw new MojoExecutionException("Failed to execute 'install_name_tool -change " + subjectName + " " + subjectPath + " " + dependentPath + + "'" + " return code: \'" + changeResult + "\'."); + } + } + } + } + + static Set findInstallNameToolCandidates(File[] files, final Log log) throws MojoExecutionException, MojoFailureException { + HashSet candidates = new HashSet(); + + for (int i = 0; i < files.length; i++) { + File file = files[i]; + + if (!file.exists()) { + continue; + } + + if (file.isDirectory()) { + candidates.addAll(findInstallNameToolCandidates(file.listFiles(), log)); + } + + String fileName = file.getName(); + if (file.isFile() && file.canWrite() && (fileName.endsWith(".so") || fileName.endsWith(".dylib") || (fileName.endsWith(".jnilib")))) { + candidates.add(file); + } + } + + return candidates; + } + + public static void makeLink(File file, final Log log) throws MojoExecutionException, MojoFailureException { + if (!file.exists()) { + return; + } + + if (file.isDirectory()) { + File[] files = file.listFiles(); + for (int i = 0; i < files.length; i++) { + makeLink(files[i], log); + } + // Run ldconfig to create soname links + runCommand("/sbin/ldconfig", new String[] { "-n", file.getPath() }, null, null, log); + } + if (file.isFile() && file.canRead() && file.canWrite() && !file.isHidden() && file.getName().matches(".*\\.so(\\.\\d+)+$")) { + File sofile = new File(file.getParent(), file.getName().substring(0, file.getName().indexOf(".so") + 3)); + if (!sofile.exists()) { + // ln -s lib.so.xx lib.so + int result = runCommand("ln", new String[] { "-s", file.getName(), sofile.getPath() }, null, null, log); + if (result != 0) { + throw new MojoExecutionException("Failed to execute 'ln -s " + file.getName() + " " + sofile.getPath() + "'" + " return code: \'" + result + + "\'."); + } + } + } + } + + /** + * Returns the header file name (javah) corresponding to the given class + * file name + * + * @param filename + * the absolute file name of the class + * @return the header file name. + */ + public static String getHeaderName(String basename, String filename) { + String base = basename.replaceAll("\\\\", "/"); + String file = filename.replaceAll("\\\\", "/"); + if (!file.startsWith(base)) { + throw new IllegalArgumentException("Error " + file + " does not start with " + base); + } + String header = file.substring(base.length() + 1); + header = header.replaceAll("/", "_"); + header = header.replaceAll("\\.class", ".h"); + return header; + } + + /** + * Replaces target with replacement in string. For jdk 1.4 compatiblity. + * + * @param target + * @param replacement + * @param string + * @return + */ + public static String replace(CharSequence target, CharSequence replacement, String string) { + return Pattern.compile(quote(target.toString())/* + * , Pattern.LITERAL jdk + * 1.4 + */).matcher(string).replaceAll( + /* Matcher. jdk 1.4 */quoteReplacement(replacement.toString())); + } + + /* for jdk 1.4 */ + private static String quote(String s) { + final String escQ = "\\Q"; + final String escE = "\\E"; + + int slashEIndex = s.indexOf(escE); + if (slashEIndex == -1) { + return escQ + s + escE; + } + + StringBuffer sb = new StringBuffer(s.length() * 2); + sb.append(escQ); + slashEIndex = 0; + int current = 0; + while ((slashEIndex = s.indexOf(escE, current)) != -1) { + sb.append(s.substring(current, slashEIndex)); + current = slashEIndex + 2; + sb.append(escE); + sb.append("\\"); + sb.append(escE); + sb.append(escQ); + } + sb.append(s.substring(current, s.length())); + sb.append(escE); + return sb.toString(); + } + + /* for jdk 1.4 */ + private static String quoteReplacement(String s) { + if ((s.indexOf('\\') == -1) && (s.indexOf('$') == -1)) { + return s; + } + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < s.length(); i++) { + char c = s.charAt(i); + if (c == '\\') { + sb.append('\\'); + sb.append('\\'); + } else if (c == '$') { + sb.append('\\'); + sb.append('$'); + } else { + sb.append(c); + } + } + return sb.toString(); + } + + public static final String DEFAULT_EXCLUDES = "**/*~,**/#*#,**/.#*,**/%*%,**/._*," + "**/CVS,**/CVS/**,**/.cvsignore," + + "**/SCCS,**/SCCS/**,**/vssver.scc," + "**/.svn,**/.svn/**,**/.DS_Store"; + + public static String getEnv(String envKey, String alternateSystemProperty, String defaultValue) { + String envValue = null; + try { + envValue = System.getenv(envKey); + if (envValue == null && alternateSystemProperty != null) { + envValue = System.getProperty(alternateSystemProperty); + } + } catch (Error e) { + // JDK 1.4? + if (alternateSystemProperty != null) { + envValue = System.getProperty(alternateSystemProperty); + } + } + + if (envValue == null) { + envValue = defaultValue; + } + + return envValue; + } + + public static String addLibraryPathToEnv(String path, Map environment, String os) { + String pathName = null; + char separator = ' '; + if (os.equals(OS.WINDOWS)) { + pathName = "Path"; + separator = ';'; + } else if (os.equals(OS.MACOSX)) { + pathName = "DYLD_LIBRARY_PATH"; + separator = ':'; + } else { + pathName = "LD_LIBRARY_PATH"; + separator = ':'; + } + + String value = environment != null ? (String) environment.get(pathName) : null; + if (value == null) { + value = NarUtil.getEnv(pathName, pathName, null); + } + + String libPath = path; + libPath = libPath.replace(File.pathSeparatorChar, separator); + if (value != null) { + value += separator + libPath; + } else { + value = libPath; + } + if (environment != null) { + environment.put(pathName, value); + } + return pathName + "=" + value; + } + + public static int runCommand(String cmd, String[] args, File workingDirectory, String[] env, final Log log) throws MojoExecutionException, + MojoFailureException { + if (log.isInfoEnabled()) { + final StringBuilder argLine = new StringBuilder(); + if (args != null) { + for (final String arg : args) { + argLine.append(" " + arg); + } + } + if (workingDirectory != null) { + log.info("+ cd " + workingDirectory.getAbsolutePath()); + } + log.info("+ " + cmd + argLine); + } + return runCommand(cmd, args, workingDirectory, env, new TextStream() { + public void println(String text) { + log.info(text); + } + }, new TextStream() { + public void println(String text) { + log.error(text); + } + + }, new TextStream() { + public void println(String text) { + log.debug(text); + } + }, log); + } + + public static int runCommand(String cmd, String[] args, File workingDirectory, String[] env, TextStream out, TextStream err, TextStream dbg, final Log log) + throws MojoExecutionException, MojoFailureException { + return runCommand(cmd, args, workingDirectory, env, out, err, dbg, log, false); + } + + public static int runCommand(String cmd, String[] args, File workingDirectory, String[] env, TextStream out, TextStream err, TextStream dbg, final Log log, + boolean expectFailure) throws MojoExecutionException, MojoFailureException { + Commandline cmdLine = new Commandline(); + + try { + dbg.println("RunCommand: " + cmd); + cmdLine.setExecutable(cmd); + if (args != null) { + for (int i = 0; i < args.length; i++) { + dbg.println(" '" + args[i] + "'"); + } + cmdLine.addArguments(args); + } + if (workingDirectory != null) { + dbg.println("in: " + workingDirectory.getPath()); + cmdLine.setWorkingDirectory(workingDirectory); + } + + if (env != null) { + dbg.println("with Env:"); + for (int i = 0; i < env.length; i++) { + String[] nameValue = env[i].split("=", 2); + if (nameValue.length < 2) { + throw new MojoFailureException(" Misformed env: '" + env[i] + "'"); + } + dbg.println(" '" + nameValue[0] + "=" + nameValue[1] + "'"); + cmdLine.addEnvironment(nameValue[0], nameValue[1]); + } + } + + Process process = cmdLine.execute(); + StreamGobbler errorGobbler = new StreamGobbler(process.getErrorStream(), err); + StreamGobbler outputGobbler = new StreamGobbler(process.getInputStream(), out); + + errorGobbler.start(); + outputGobbler.start(); + process.waitFor(); + int exitValue = process.exitValue(); + dbg.println("ExitValue: " + exitValue); + final int timeout = 5000; + errorGobbler.join(timeout); + outputGobbler.join(timeout); + if (exitValue != 0 ^ expectFailure) { + if (log == null) { + System.err.println(err.toString()); + System.err.println(out.toString()); + System.err.println(dbg.toString()); + } else { + log.warn(err.toString()); + log.warn(out.toString()); + log.warn(dbg.toString()); + } + throw new MojoExecutionException("exit code: " + exitValue); + } + return exitValue; + } catch (MojoExecutionException e) { + throw e; + } catch (Exception e) { + throw new MojoExecutionException("Could not launch " + cmdLine, e); + } + } + + private static final class StreamGobbler extends Thread { + private InputStream is; + + private TextStream ts; + + private StreamGobbler(InputStream is, TextStream ts) { + this.is = is; + this.ts = ts; + } + + public void run() { + try { + BufferedReader reader = new BufferedReader(new InputStreamReader(is)); + String line = null; + while ((line = reader.readLine()) != null) { + ts.println(line); + } + reader.close(); + } catch (IOException e) { + // e.printStackTrace() + StackTraceElement[] stackTrace = e.getStackTrace(); + for (int i = 0; i < stackTrace.length; i++) { + ts.println(stackTrace[i].toString()); + } + } + } + } + + /** + * (Darren) this code lifted from mvn help:active-profiles plugin Recurses + * into the project's parent poms to find the active profiles of the + * specified project and all its parents. + * + * @param project + * The project to start with + * @return A list of active profiles + */ + static List collectActiveProfiles(MavenProject project) { + List profiles = project.getActiveProfiles(); + + if (project.hasParent()) { + profiles.addAll(collectActiveProfiles(project.getParent())); + } + + return profiles; + } } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/OS.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/OS.java index de2bc0c..bfb34a0 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/OS.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/OS.java @@ -22,14 +22,13 @@ /** * @author Mark Donszelmann */ -public interface OS -{ +public interface OS { - String MACOSX = "MacOSX"; + String MACOSX = "MacOSX"; - String WINDOWS = "Windows"; + String WINDOWS = "Windows"; - String LINUX = "Linux"; + String LINUX = "Linux"; - String SUNOS = "SunOS"; + String SUNOS = "SunOS"; } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/ProcessLibraryCommand.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/ProcessLibraryCommand.java index 1151e03..f42a348 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/ProcessLibraryCommand.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/ProcessLibraryCommand.java @@ -23,50 +23,54 @@ import java.util.List; public class ProcessLibraryCommand { - - /** - * The executable to run - * - * @parameter default-value="" - */ - private String executable; - - /** - * The library type that this command is valid for - * - * @parameter default-value="" - */ - private String libraryType; - - /** - * Any additional arguments to pass into the executable - * - * @parameter default-value="" - */ - private List arguments; - - public List getCommandList() { - List command = new ArrayList(); - command.add(executable); - command.addAll(arguments); - return command; - } - - public String getExecutable() { - return executable; - } - public void setExecutable(String executable) { - this.executable = executable; - } - public List getArguments() { - return arguments; - } - public void setArguments(List arguments) { - this.arguments = arguments; - } - public String getType() { - // TODO Auto-generated method stub - return libraryType; - } + + /** + * The executable to run + * + * @parameter default-value="" + */ + private String executable; + + /** + * The library type that this command is valid for + * + * @parameter default-value="" + */ + private String libraryType; + + /** + * Any additional arguments to pass into the executable + * + * @parameter default-value="" + */ + private List arguments; + + public List getCommandList() { + List command = new ArrayList(); + command.add(executable); + command.addAll(arguments); + return command; + } + + public String getExecutable() { + return executable; + } + + public void setExecutable(String executable) { + this.executable = executable; + } + + public List getArguments() { + return arguments; + } + + public void setArguments(List arguments) { + this.arguments = arguments; + } + + public String getType() { + // TODO Auto-generated method stub + return libraryType; + } } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Resource.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Resource.java index 7812e36..6545814 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Resource.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Resource.java @@ -24,15 +24,11 @@ * * @author Greg Domjan */ -public class Resource - extends Compiler -{ - public Resource() - { - } +public class Resource extends Compiler { + public Resource() { + } - public final String getLanguage() - { - return "res"; - } + public final String getLanguage() { + return "res"; + } } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/StringTextStream.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/StringTextStream.java index 545fde8..e8151c3 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/StringTextStream.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/StringTextStream.java @@ -25,31 +25,27 @@ * @author Mark Donszelmann (Mark.Donszelmann@gmail.com) * @version $Id$ */ -public class StringTextStream - implements TextStream -{ - private StringBuffer sb; +public class StringTextStream implements TextStream { + private StringBuffer sb; - private String lineSeparator; + private String lineSeparator; - public StringTextStream() - { - sb = new StringBuffer(); - lineSeparator = System.getProperty( "line.separator", "\n" ); - } + public StringTextStream() { + sb = new StringBuffer(); + lineSeparator = System.getProperty("line.separator", "\n"); + } - /* - * (non-Javadoc) - * @see com.github.maven_nar.TextStream#println(java.lang.String) - */ - public final void println( String text ) - { - sb.append( text ); - sb.append( lineSeparator ); - } + /* + * (non-Javadoc) + * + * @see com.github.maven_nar.TextStream#println(java.lang.String) + */ + public final void println(String text) { + sb.append(text); + sb.append(lineSeparator); + } - public final String toString() - { - return sb.toString(); - } + public final String toString() { + return sb.toString(); + } } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/SysLib.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/SysLib.java index daf831e..9e7a0c4 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/SysLib.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/SysLib.java @@ -29,32 +29,35 @@ * * @author Mark Donszelmann */ -public class SysLib implements ISysLib -{ - /** - * Name of the system library - * - * @parameter default-value="" - * @required - */ - private String name; +public class SysLib implements ISysLib { + /** + * Name of the system library + * + * @parameter default-value="" + * @required + */ + private String name; - /** - * Type of linking for this system library - * - * @parameter default-value="shared" - * @required - */ - private String type = ILibrary.SHARED; + /** + * Type of linking for this system library + * + * @parameter default-value="shared" + * @required + */ + private String type = ILibrary.SHARED; - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see com.github.maven_nar.ISysLib#getName() */ public String getName() { return name; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see com.github.maven_nar.ISysLib#getType() */ public String getType() { @@ -68,6 +71,5 @@ protected void setName(String name) { protected void setType(String type) { this.type = type; } - - + } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Test.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Test.java index 4d9bce0..319b30e 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Test.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Test.java @@ -32,61 +32,55 @@ * * @author Mark Donszelmann */ -public class Test - implements ITest -{ +public class Test implements ITest { - /** - * Name of the test to create - * - * @required - * @parameter default-value="" - */ - private String name = null; + /** + * Name of the test to create + * + * @required + * @parameter default-value="" + */ + private String name = null; - /** - * Type of linking used for this test Possible choices are: "shared" or "static". Defaults to "shared". - * - * @parameter default-value="" - */ - private String link = ILibrary.SHARED; + /** + * Type of linking used for this test Possible choices are: "shared" or + * "static". Defaults to "shared". + * + * @parameter default-value="" + */ + private String link = ILibrary.SHARED; - /** - * When true run this test. Defaults to true; - * - * @parameter expresssion="" - */ - private boolean run = true; + /** + * When true run this test. Defaults to true; + * + * @parameter expresssion="" + */ + private boolean run = true; - /** - * Arguments to be used for running this test. Defaults to empty list. This option is only used if run=true. - * - * @parameter default-value="" - */ - private List/* */args = new ArrayList(); + /** + * Arguments to be used for running this test. Defaults to empty list. This + * option is only used if run=true. + * + * @parameter default-value="" + */ + private List/* */args = new ArrayList(); - public final String getName() - throws MojoFailureException - { - if ( name == null ) - { - throw new MojoFailureException( "NAR: Please specify as part of " ); - } - return name; - } + public final String getName() throws MojoFailureException { + if (name == null) { + throw new MojoFailureException("NAR: Please specify as part of "); + } + return name; + } - public final String getLink() - { - return link; - } + public final String getLink() { + return link; + } - public final boolean shouldRun() - { - return run; - } + public final boolean shouldRun() { + return run; + } - public final List/* */getArgs() - { - return args; - } + public final List/* */getArgs() { + return args; + } } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/TextStream.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/TextStream.java index b9bddf8..ef4d8a7 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/TextStream.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/TextStream.java @@ -25,7 +25,6 @@ * @author Mark Donszelmann (Mark.Donszelmann@gmail.com) * @version $Id$ */ -public interface TextStream -{ - void println(String text); +public interface TextStream { + void println(String text); } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/MavenNarPlugin.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/MavenNarPlugin.java index c0acbcc..4eac191 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/MavenNarPlugin.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/MavenNarPlugin.java @@ -57,8 +57,7 @@ public void log(String message, Exception e) { public MavenNarPlugin() { instance = this; - if (Boolean.parseBoolean(Platform.getDebugOption(PLUGIN_ID - + "/debug/initialization"))) { + if (Boolean.parseBoolean(Platform.getDebugOption(PLUGIN_ID + "/debug/initialization"))) { System.err.println("### executing constructor " + PLUGIN_ID); new Throwable().printStackTrace(); } @@ -70,17 +69,15 @@ public MavenNarPlugin() { public void start(BundleContext bundleContext) throws Exception { super.start(bundleContext); - if (Boolean.parseBoolean(Platform.getDebugOption(PLUGIN_ID - + "/debug/initialization"))) { + if (Boolean.parseBoolean(Platform.getDebugOption(PLUGIN_ID + "/debug/initialization"))) { System.err.println("### executing start() " + PLUGIN_ID); new Throwable().printStackTrace(); } - + // Make sure the m2e jdt plugin is initialised first MavenJdtPlugin.getDefault(); - MavenProjectManager projectManager = MavenPluginActivator.getDefault() - .getMavenProjectManager(); + MavenProjectManager projectManager = MavenPluginActivator.getDefault().getMavenProjectManager(); this.buildpathManager = new BuildPathManager(projectManager); projectManager.addMavenProjectChangedListener(this.buildpathManager); @@ -101,8 +98,7 @@ public void start(BundleContext bundleContext) throws Exception { * @noreference see class javadoc */ public void stop(BundleContext context) throws Exception { - MavenProjectManager projectManager = MavenPluginActivator.getDefault() - .getMavenProjectManager(); + MavenProjectManager projectManager = MavenPluginActivator.getDefault().getMavenProjectManager(); projectManager.removeMavenProjectChangedListener(buildpathManager); /* diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/BuildPathManager.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/BuildPathManager.java index e30d435..c7c60cc 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/BuildPathManager.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/BuildPathManager.java @@ -55,8 +55,7 @@ public BuildPathManager(IMavenProjectRegistry projectManager) { } @Override - public void mavenProjectChanged(MavenProjectChangedEvent[] events, - IProgressMonitor monitor) { + public void mavenProjectChanged(MavenProjectChangedEvent[] events, IProgressMonitor monitor) { monitor.setTaskName(Messages.BuildPathManager_setting_paths); final Set projects = new HashSet(); for (final MavenProjectChangedEvent event : events) { @@ -64,8 +63,7 @@ public void mavenProjectChanged(MavenProjectChangedEvent[] events, if (project.isAccessible() && projects.add(project)) { try { updateBuildPaths(project, monitor); - } - catch (final CoreException e) { + } catch (final CoreException e) { MavenNarPlugin.getDefault().logError("Problem when updating build paths", e); } } @@ -75,24 +73,19 @@ public void mavenProjectChanged(MavenProjectChangedEvent[] events, private void updateBuildPaths(IProject project, IProgressMonitor monitor) throws CoreException { final IMavenProjectFacade facade = projectManager.getProject(project); if (facade != null) { - final ICProjectDescriptionManager mngr = CoreModel.getDefault() - .getProjectDescriptionManager(); - final ICProjectDescription des = mngr.getProjectDescription(project, - true); + final ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); + final ICProjectDescription des = mngr.getProjectDescription(project, true); if (des != null) { boolean changed = false; logger.debug("updateBuildPaths: project=" + project.getName()); final ConfiguratorContext context = new ConfiguratorContext(MavenPlugin.getMaven(), projectManager); - List narExecutions = MavenUtils.buildCompileNarExecutions(context, - facade, monitor); - narExecutions.addAll(MavenUtils.buildTestCompileNarExecutions(context, - facade, monitor)); + List narExecutions = MavenUtils.buildCompileNarExecutions(context, facade, monitor); + narExecutions.addAll(MavenUtils.buildTestCompileNarExecutions(context, facade, monitor)); for (NarExecution narSettings : narExecutions) { if (!narSettings.isSkip()) { final String os = narSettings.getOS(); final String linkerName = narSettings.getLinkerName(); - final AbstractSettingsSynchroniser synchro = SynchroniserFactory.getSettingsSynchroniser( - os, linkerName); + final AbstractSettingsSynchroniser synchro = SynchroniserFactory.getSettingsSynchroniser(os, linkerName); changed = updateCdtBuildPaths(des, synchro, narSettings); } } @@ -103,19 +96,17 @@ private void updateBuildPaths(IProject project, IProgressMonitor monitor) throws } } - private boolean updateCdtBuildPaths(final ICProjectDescription des, final SettingsSynchroniser synchro, - final NarExecution narSettings) throws CoreException { + private boolean updateCdtBuildPaths(final ICProjectDescription des, final SettingsSynchroniser synchro, final NarExecution narSettings) + throws CoreException { boolean changed = false; - for (NarBuildArtifact artifactSettings : narSettings - .getArtifactSettings()) { + for (NarBuildArtifact artifactSettings : narSettings.getArtifactSettings()) { final String configName = artifactSettings.getConfigName(); final ICConfigurationDescription cfg = des.getConfigurationByName(configName); if (cfg != null) { logger.debug("updateBuildPaths: updating config " + configName); synchro.pathsOnlySync(cfg, artifactSettings); changed = true; - } - else { + } else { logger.debug("updateBuildPaths: could not find config " + configName); } } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/CProjectConfigurator.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/CProjectConfigurator.java index 713304d..77dc814 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/CProjectConfigurator.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/CProjectConfigurator.java @@ -75,46 +75,35 @@ public class CProjectConfigurator extends AbstractProjectConfigurator { public static final String CONFIGURATOR_ID = "com.github.sdedwards.m2e_nar.cConfigurator"; @Override - public void configure(ProjectConfigurationRequest request, - IProgressMonitor monitor) throws CoreException { + public void configure(ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException { - final ConfiguratorContext context = new ConfiguratorContext(maven, - projectManager); + final ConfiguratorContext context = new ConfiguratorContext(maven, projectManager); IProject project = request.getProject(); - monitor.setTaskName(Messages.CProjectConfigurator_task_name - + project.getName()); + monitor.setTaskName(Messages.CProjectConfigurator_task_name + project.getName()); logger.info("configure"); - ICProjectDescriptionManager mngr = CoreModel.getDefault() - .getProjectDescriptionManager(); + ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); // Set the first created configuration as active. boolean setActive = true; final IMavenProjectFacade facade = request.getMavenProjectFacade(); - List narExecutions = MavenUtils.buildCompileNarExecutions(context, - facade, monitor); - narExecutions.addAll(MavenUtils.buildTestCompileNarExecutions(context, - facade, monitor)); + List narExecutions = MavenUtils.buildCompileNarExecutions(context, facade, monitor); + narExecutions.addAll(MavenUtils.buildTestCompileNarExecutions(context, facade, monitor)); for (NarExecution narSettings : narExecutions) { if (!narSettings.isSkip()) { final String os = narSettings.getOS(); final String linkerName = narSettings.getLinkerName(); - final AbstractSettingsSynchroniser synchro = SynchroniserFactory - .getSettingsSynchroniser(os, linkerName); + final AbstractSettingsSynchroniser synchro = SynchroniserFactory.getSettingsSynchroniser(os, linkerName); final String toolchain = synchro.getToolchain(); - for (NarBuildArtifact artifactSettings : narSettings - .getArtifactSettings()) { + for (NarBuildArtifact artifactSettings : narSettings.getArtifactSettings()) { final String configName = artifactSettings.getConfigName(); - final String cdtArtefactType = CdtUtils - .convertArtefactType(artifactSettings.getType()); + final String cdtArtefactType = CdtUtils.convertArtefactType(artifactSettings.getType()); IToolChain tc = getToolChain(toolchain, cdtArtefactType); - ICProjectDescription desc = getCdtProject(project, tc, - cdtArtefactType, monitor); - ICConfigurationDescription cfg = getCdtMavenConfig(project, - desc, tc, cdtArtefactType, configName, setActive, monitor); + ICProjectDescription desc = getCdtProject(project, tc, cdtArtefactType, monitor); + ICConfigurationDescription cfg = getCdtMavenConfig(project, desc, tc, cdtArtefactType, configName, setActive, monitor); setActive = false; synchro.fullSync(cfg, artifactSettings); mngr.setProjectDescription(project, desc); @@ -132,11 +121,9 @@ public void configure(ProjectConfigurationRequest request, ICommand mavenBuilder = null; ArrayList newSpec = new ArrayList(); for (ICommand command : description.getBuildSpec()) { - if (ManagedCProjectNature.getBuilderID().equals(command.getBuilderName()) && - mavenBuilder == null) { + if (ManagedCProjectNature.getBuilderID().equals(command.getBuilderName()) && mavenBuilder == null) { cdtBuilder = command; - } - else { + } else { newSpec.add(command); } if (IMavenConstants.BUILDER_ID.equals(command.getBuilderName())) { @@ -154,9 +141,7 @@ public void configure(ProjectConfigurationRequest request, } @Override - public AbstractBuildParticipant getBuildParticipant( - IMavenProjectFacade projectFacade, MojoExecution execution, - IPluginExecutionMetadata executionMetadata) { + public AbstractBuildParticipant getBuildParticipant(IMavenProjectFacade projectFacade, MojoExecution execution, IPluginExecutionMetadata executionMetadata) { final String goal = execution.getGoal(); if ("nar-validate".equals(goal)) { return new MojoExecutionBuildParticipant(execution, false, true); @@ -197,19 +182,16 @@ public AbstractBuildParticipant getBuildParticipant( } else if ("nar-test".equals(goal)) { return null; } - return super.getBuildParticipant(projectFacade, execution, - executionMetadata); + return super.getBuildParticipant(projectFacade, execution, executionMetadata); } @Override - public void unconfigure(ProjectConfigurationRequest request, - IProgressMonitor monitor) throws CoreException { + public void unconfigure(ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException { super.unconfigure(request, monitor); // removeMavenClasspathContainer(request.getProject()); } - protected void addCppNature(IProject project, IProgressMonitor monitor) - throws CoreException { + protected void addCppNature(IProject project, IProgressMonitor monitor) throws CoreException { CProjectNature.addCNature(project, monitor); } @@ -226,8 +208,7 @@ protected boolean isValid(IToolChain tc) { */ // Filter off unsupported and system toolchains - if (tc == null || !tc.isSupported() || tc.isAbstract() - || tc.isSystemObject()) + if (tc == null || !tc.isSupported() || tc.isAbstract() || tc.isSystemObject()) return false; // Check for platform compatibility @@ -240,9 +221,7 @@ protected boolean isValid(IConfiguration cfg) { protected List getCfgs(IToolChain tc, String artefactType) { List out = new ArrayList(); - IConfiguration[] cfgs = ManagedBuildManager.getExtensionConfigurations( - tc, ManagedBuildManager.BUILD_ARTEFACT_TYPE_PROPERTY_ID, - artefactType); + IConfiguration[] cfgs = ManagedBuildManager.getExtensionConfigurations(tc, ManagedBuildManager.BUILD_ARTEFACT_TYPE_PROPERTY_ID, artefactType); if (cfgs != null) { for (IConfiguration cfg : cfgs) { if (isValid(cfg)) { @@ -278,13 +257,10 @@ protected List getCfgs(IToolChain tc, String artefactType) { * } } return ls.toArray(new CfgHolder[ls.size()]); } */ - private IToolChain getToolChain(final String toolChain, - final String artefactType) throws CoreException { + private IToolChain getToolChain(final String toolChain, final String artefactType) throws CoreException { // Find the tool chains supported on our system for the selected // artefact type - IToolChain[] tcs = ManagedBuildManager.getExtensionsToolChains( - ManagedBuildManager.BUILD_ARTEFACT_TYPE_PROPERTY_ID, - artefactType, true); + IToolChain[] tcs = ManagedBuildManager.getExtensionsToolChains(ManagedBuildManager.BUILD_ARTEFACT_TYPE_PROPERTY_ID, artefactType, true); // Find the tool chain IToolChain tc = null; for (IToolChain tc2 : tcs) { @@ -294,66 +270,47 @@ private IToolChain getToolChain(final String toolChain, } } if (tc == null) { - throw new CoreException(new Status(IStatus.ERROR, - MavenNarPlugin.PLUGIN_ID, - "Could not find valid tool chain \"" + toolChain + "\"")); + throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Could not find valid tool chain \"" + toolChain + "\"")); } return tc; } - private ICProjectDescription getCdtProject(IProject project, IToolChain tc, - String artefactType, IProgressMonitor monitor) throws CoreException { + private ICProjectDescription getCdtProject(IProject project, IToolChain tc, String artefactType, IProgressMonitor monitor) throws CoreException { try { - ICProjectDescriptionManager mngr = CoreModel.getDefault() - .getProjectDescriptionManager(); + ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); if (!project.hasNature(CCProjectNature.CC_NATURE_ID)) { - MavenNarPlugin.getDefault().log( - "Configuring project with " + tc.getUniqueRealName() - + " tool chain"); + MavenNarPlugin.getDefault().log("Configuring project with " + tc.getUniqueRealName() + " tool chain"); // Add the C++ Nature - CCorePlugin.getDefault().convertProjectToNewCC(project, - ManagedBuildManager.CFG_DATA_PROVIDER_ID, monitor); - ICProjectDescription des = mngr.createProjectDescription( - project, false, false); - IManagedBuildInfo info = ManagedBuildManager - .createBuildInfo(project); + CCorePlugin.getDefault().convertProjectToNewCC(project, ManagedBuildManager.CFG_DATA_PROVIDER_ID, monitor); + ICProjectDescription des = mngr.createProjectDescription(project, false, false); + IManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project); List cfgs = getCfgs(tc, artefactType); if (cfgs.isEmpty()) { - throw new CoreException(new Status(IStatus.ERROR, - MavenNarPlugin.PLUGIN_ID, - "Cannot find any configurations")); + throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Cannot find any configurations")); } IConfiguration cf = cfgs.get(0); - IManagedProject mProj = ManagedBuildManager - .createManagedProject(project, cf.getProjectType()); + IManagedProject mProj = ManagedBuildManager.createManagedProject(project, cf.getProjectType()); info.setManagedProject(mProj); return des; } else { - ICProjectDescription des = mngr.getProjectDescription(project, - true); + ICProjectDescription des = mngr.getProjectDescription(project, true); return des; } } catch (BuildException e) { - throw new CoreException(new Status(IStatus.ERROR, - MavenNarPlugin.PLUGIN_ID, - "Cannot create CDT managed project", e)); + throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Cannot create CDT managed project", e)); } } - private ICConfigurationDescription getCdtMavenConfig(IProject project, - ICProjectDescription des, IToolChain tc, String artefactType, - String name, boolean setActive, IProgressMonitor monitor) throws CoreException { - IManagedProject mProj = ManagedBuildManager.getBuildInfo(project) - .getManagedProject(); + private ICConfigurationDescription getCdtMavenConfig(IProject project, ICProjectDescription des, IToolChain tc, String artefactType, String name, + boolean setActive, IProgressMonitor monitor) throws CoreException { + IManagedProject mProj = ManagedBuildManager.getBuildInfo(project).getManagedProject(); ICConfigurationDescription mavenCfg = des.getConfigurationByName(name); if (mavenCfg == null) { List cfgs = getCfgs(tc, artefactType); if (cfgs.isEmpty()) { - throw new CoreException(new Status(IStatus.ERROR, - MavenNarPlugin.PLUGIN_ID, - "Cannot find any configurations")); + throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Cannot find any configurations")); } monitor.worked(10); monitor.worked(10); @@ -366,13 +323,8 @@ private ICConfigurationDescription getCdtMavenConfig(IProject project, int work = 50 / cfgs.size(); for (IConfiguration cfg : cfgs) { - IBuildProperty b = cfg.getBuildProperties().getProperty( - ManagedBuildManager.BUILD_TYPE_PROPERTY_ID); - if (cfgRelease == null - && b != null - && b.getValue() != null - && ManagedBuildManager.BUILD_TYPE_PROPERTY_RELEASE - .equals(b.getValue().getId())) { + IBuildProperty b = cfg.getBuildProperties().getProperty(ManagedBuildManager.BUILD_TYPE_PROPERTY_ID); + if (cfgRelease == null && b != null && b.getValue() != null && ManagedBuildManager.BUILD_TYPE_PROPERTY_RELEASE.equals(b.getValue().getId())) { cfgRelease = cfg; } if (cfgFirst == null) { @@ -384,14 +336,11 @@ private ICConfigurationDescription getCdtMavenConfig(IProject project, if (cfgRelease != null) { cfgFirst = cfgRelease; } - MavenNarPlugin.getDefault().log( - "Creating configuration " + name); - IConfiguration newCfg = createConfiguration(cfgFirst, mProj, - des); + MavenNarPlugin.getDefault().log("Creating configuration " + name); + IConfiguration newCfg = createConfiguration(cfgFirst, mProj, des); newCfg.setName(name); newCfg.setDescription("m2e generated configuration"); - mavenCfg = ManagedBuildManager - .getDescriptionForConfiguration(newCfg); + mavenCfg = ManagedBuildManager.getDescriptionForConfiguration(newCfg); } } if (mavenCfg != null) { @@ -400,29 +349,23 @@ private ICConfigurationDescription getCdtMavenConfig(IProject project, } return mavenCfg; } else { - throw new CoreException(new Status(IStatus.ERROR, - MavenNarPlugin.PLUGIN_ID, "Cannot find any configurations")); + throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Cannot find any configurations")); } // mngr.setProjectDescription(project, des); } - private IConfiguration createConfiguration(IConfiguration cfg, - IManagedProject proj, ICProjectDescription des) - throws WriteAccessException, CoreException { + private IConfiguration createConfiguration(IConfiguration cfg, IManagedProject proj, ICProjectDescription des) throws WriteAccessException, CoreException { String id = ManagedBuildManager.calculateChildId(cfg.getId(), null); // CProjectDescriptionManager.getInstance(); - Configuration config = new Configuration((ManagedProject) proj, - (Configuration) cfg, id, false, true); + Configuration config = new Configuration((ManagedProject) proj, (Configuration) cfg, id, false, true); CConfigurationData data = config.getConfigurationData(); - ICConfigurationDescription cfgDes = des.createConfiguration( - ManagedBuildManager.CFG_DATA_PROVIDER_ID, data); + ICConfigurationDescription cfgDes = des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data); config.setConfigurationDescription(cfgDes); config.exportArtifactInfo(); // Force internal builder IBuilder internalBuilder = ManagedBuildManager.getInternalBuilder(); - config.changeBuilder(internalBuilder, internalBuilder.getId(), - internalBuilder.getName()); + config.changeBuilder(internalBuilder, internalBuilder.getId(), internalBuilder.getName()); // IBuilder bld = config.getEditableBuilder(); // if (bld != null) { bld.setManagedBuildOn(true); } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/ConfiguratorContext.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/ConfiguratorContext.java index e243cb5..77d39c9 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/ConfiguratorContext.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/ConfiguratorContext.java @@ -25,7 +25,7 @@ public class ConfiguratorContext { private final IMaven maven; private final IMavenProjectRegistry projectManager; - + public ConfiguratorContext(final IMaven maven, final IMavenProjectRegistry projectManager) { this.maven = maven; this.projectManager = projectManager; diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/INarExecutionBuilder.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/INarExecutionBuilder.java index 00976cd..e9dcb97 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/INarExecutionBuilder.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/INarExecutionBuilder.java @@ -26,5 +26,5 @@ public interface INarExecutionBuilder { public abstract NarExecution build(String buildType) throws CoreException; - + } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/MavenUtils.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/MavenUtils.java index d10ecbc..f8ab8f2 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/MavenUtils.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/MavenUtils.java @@ -70,94 +70,71 @@ public final class MavenUtils { public static String NAR_COMPILE_GOAL = "nar-compile"; public static String NAR_TESTCOMPILE_GOAL = "nar-testCompile"; - + public static String NAR_TESTUNPACK_GOAL = "nar-testUnpack"; public static String NAR_TEST_UNPACK_GOAL = "nar-test-unpack"; - + private static final Logger logger = LoggerFactory.getLogger(MavenUtils.class); private static ClassRealm realm = null; - private static T loadMojo(final IMaven maven, - final MavenProject project, final MojoExecution mojoExecution, - final Class asType, final IProgressMonitor monitor) - throws CoreException { - return maven.createExecutionContext().execute(project, - new ICallable() { - public T call(IMavenExecutionContext context, - IProgressMonitor monitor) throws CoreException { - return maven.getConfiguredMojo(context.getSession(), - mojoExecution, asType); - } - }, monitor); + private static T loadMojo(final IMaven maven, final MavenProject project, final MojoExecution mojoExecution, final Class asType, + final IProgressMonitor monitor) throws CoreException { + return maven.createExecutionContext().execute(project, new ICallable() { + public T call(IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException { + return maven.getConfiguredMojo(context.getSession(), mojoExecution, asType); + } + }, monitor); } - private static void releaseMojo(final IMaven maven, - final MavenProject project, final Object mojo, - final MojoExecution mojoExecution, final IProgressMonitor monitor) - throws CoreException { - maven.createExecutionContext().execute(project, - new ICallable() { - public Boolean call(IMavenExecutionContext context, - IProgressMonitor monitor) throws CoreException { - maven.releaseMojo(mojo, mojoExecution); - return true; - } - }, monitor); + private static void releaseMojo(final IMaven maven, final MavenProject project, final Object mojo, final MojoExecution mojoExecution, + final IProgressMonitor monitor) throws CoreException { + maven.createExecutionContext().execute(project, new ICallable() { + public Boolean call(IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException { + maven.releaseMojo(mojo, mojoExecution); + return true; + } + }, monitor); } - private static synchronized ClassRealm getMyRealm(ClassWorld world) - throws CoreException { + private static synchronized ClassRealm getMyRealm(ClassWorld world) throws CoreException { try { if (realm == null) { - realm = world.newRealm(MavenNarPlugin.PLUGIN_ID, - CProjectConfigurator.class.getClassLoader()); + realm = world.newRealm(MavenNarPlugin.PLUGIN_ID, CProjectConfigurator.class.getClassLoader()); } return realm; } catch (DuplicateRealmException e) { - throw new CoreException(new Status(IStatus.ERROR, - MavenNarPlugin.PLUGIN_ID, - "Problem when creating realm", e)); + throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Problem when creating realm", e)); } } - private static T getConfiguredMojo(final IMaven maven, - final MavenProject project, final MojoExecution mojoExecution, + private static T getConfiguredMojo(final IMaven maven, final MavenProject project, final MojoExecution mojoExecution, final Class asType, final Log log, final IProgressMonitor monitor) throws CoreException { - return maven.createExecutionContext().execute(project, - new ICallable() { - public T call(IMavenExecutionContext context, - IProgressMonitor monitor) throws CoreException { - return getConfiguredMojo(context.getSession(), - mojoExecution, asType, log); - } - - }, monitor); + return maven.createExecutionContext().execute(project, new ICallable() { + public T call(IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException { + return getConfiguredMojo(context.getSession(), mojoExecution, asType, log); + } + + }, monitor); } - private static T getConfiguredMojo(MavenSession session, - MojoExecution mojoExecution, Class asType, Log log) throws CoreException { + private static T getConfiguredMojo(MavenSession session, MojoExecution mojoExecution, Class asType, Log log) + throws CoreException { MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); - PluginDescriptor pluginDescriptor = mojoDescriptor - .getPluginDescriptor(); + PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor(); - ClassRealm pluginRealm = getMyRealm(pluginDescriptor.getClassRealm() - .getWorld()); + ClassRealm pluginRealm = getMyRealm(pluginDescriptor.getClassRealm().getWorld()); T mojo; try { mojo = asType.newInstance(); + } catch (Exception e) { + throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Problem when creating mojo", e)); } - catch (Exception e) { - throw new CoreException(new Status(IStatus.ERROR, - MavenNarPlugin.PLUGIN_ID, - "Problem when creating mojo", e)); - } - + mojo.setLog(log); - logger.debug("Configuring mojo " + mojoDescriptor.getId() - + " from plugin realm " + pluginRealm); + logger.debug("Configuring mojo " + mojoDescriptor.getId() + " from plugin realm " + pluginRealm); Xpp3Dom dom = mojoExecution.getConfiguration(); @@ -169,95 +146,66 @@ private static T getConfiguredMojo(MavenSession session pomConfiguration = new XmlPlexusConfiguration(dom); } - ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( - session, mojoExecution); + ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator(session, mojoExecution); - populatePluginFields(mojo, mojoDescriptor, pluginRealm, - pomConfiguration, expressionEvaluator); + populatePluginFields(mojo, mojoDescriptor, pluginRealm, pomConfiguration, expressionEvaluator); return mojo; } - private static void populatePluginFields(Object mojo, - MojoDescriptor mojoDescriptor, ClassRealm pluginRealm, - PlexusConfiguration configuration, + private static void populatePluginFields(Object mojo, MojoDescriptor mojoDescriptor, ClassRealm pluginRealm, PlexusConfiguration configuration, ExpressionEvaluator expressionEvaluator) throws CoreException { ComponentConfigurator configurator = new BasicComponentConfigurator(); try { - configurator.configureComponent(mojo, configuration, - expressionEvaluator, pluginRealm); + configurator.configureComponent(mojo, configuration, expressionEvaluator, pluginRealm); } catch (ComponentConfigurationException e) { - String message = "Unable to parse configuration of mojo " - + mojoDescriptor.getId(); + String message = "Unable to parse configuration of mojo " + mojoDescriptor.getId(); if (e.getFailedConfiguration() != null) { - message += " for parameter " - + e.getFailedConfiguration().getName(); + message += " for parameter " + e.getFailedConfiguration().getName(); } message += ": " + e.getMessage(); - throw new CoreException(new Status(IStatus.ERROR, - MavenNarPlugin.PLUGIN_ID, message, e)); + throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, message, e)); } catch (NoClassDefFoundError e) { ByteArrayOutputStream os = new ByteArrayOutputStream(1024); PrintStream ps = new PrintStream(os); - ps.println("A required class was missing during configuration of mojo " - + mojoDescriptor.getId() + ": " + e.getMessage()); + ps.println("A required class was missing during configuration of mojo " + mojoDescriptor.getId() + ": " + e.getMessage()); pluginRealm.display(ps); - throw new CoreException(new Status(IStatus.ERROR, - MavenNarPlugin.PLUGIN_ID, os.toString(), e)); + throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, os.toString(), e)); } catch (LinkageError e) { ByteArrayOutputStream os = new ByteArrayOutputStream(1024); PrintStream ps = new PrintStream(os); - ps.println("An API incompatibility was encountered during configuration of mojo " - + mojoDescriptor.getId() - + ": " - + e.getClass().getName() - + ": " + e.getMessage()); + ps.println("An API incompatibility was encountered during configuration of mojo " + mojoDescriptor.getId() + ": " + e.getClass().getName() + ": " + + e.getMessage()); pluginRealm.display(ps); - throw new CoreException(new Status(IStatus.ERROR, - MavenNarPlugin.PLUGIN_ID, os.toString(), e)); + throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, os.toString(), e)); } } - public static NarExecution readCompileSettings( - final ConfiguratorContext context, - final IMavenProjectFacade facade, - final MojoExecution compileExecution, - final IProgressMonitor monitor) - throws CoreException { + public static NarExecution readCompileSettings(final ConfiguratorContext context, final IMavenProjectFacade facade, final MojoExecution compileExecution, + final IProgressMonitor monitor) throws CoreException { return readSettings(context, facade, compileExecution, NarCompileMojo.class, NarExecution.MAIN, monitor); } - - public static NarExecution readTestCompileSettings( - final ConfiguratorContext context, - final IMavenProjectFacade facade, - final MojoExecution compileExecution, - final IProgressMonitor monitor) - throws CoreException { + + public static NarExecution readTestCompileSettings(final ConfiguratorContext context, final IMavenProjectFacade facade, + final MojoExecution compileExecution, final IProgressMonitor monitor) throws CoreException { return readSettings(context, facade, compileExecution, NarTestCompileMojo.class, NarExecution.TEST, monitor); } - - public static NarExecution readSettings( - final ConfiguratorContext context, - final IMavenProjectFacade facade, - final MojoExecution compileExecution, - final Class mojoType, - final String buildType, - final IProgressMonitor monitor) - throws CoreException { + + public static NarExecution readSettings(final ConfiguratorContext context, final IMavenProjectFacade facade, + final MojoExecution compileExecution, final Class mojoType, final String buildType, final IProgressMonitor monitor) throws CoreException { final IMaven maven = context.getMaven(); final MavenProject mavenProject = facade.getMavenProject(); NarExecution settings = null; if (compileExecution != null) { // Load plugin with Maven in order to check config // and to get at aol.properties resource inside the plugin - AbstractMojo narMojo = loadMojo(maven, mavenProject, - compileExecution, AbstractMojo.class, monitor); + AbstractMojo narMojo = loadMojo(maven, mavenProject, compileExecution, AbstractMojo.class, monitor); try { // ClassRealm pluginRealm = // compileExecution.getMojoDescriptor().getPluginDescriptor().getClassRealm(); @@ -266,59 +214,39 @@ public static NarExecution readSettings( // classloader.createNarExecutionBuilder(mavenProject, // compileMojo); // settings = builder.build(NarExecution.MAIN); - T compileMojo = getConfiguredMojo(maven, - mavenProject, compileExecution, mojoType, narMojo.getLog(), monitor); - compileMojo.setNarProperties(new NarProperties(mavenProject, - narMojo.getClass())); + T compileMojo = getConfiguredMojo(maven, mavenProject, compileExecution, mojoType, narMojo.getLog(), monitor); + compileMojo.setNarProperties(new NarProperties(mavenProject, narMojo.getClass())); // Need to call validate to set up defaults compileMojo.validate(); // Resolve the NAR artifacts, possibly from workspace compileMojo.prepareNarArtifacts(context, facade, monitor); - NarExecutionBuilder builder = new NarExecutionBuilder( - compileMojo, compileExecution); + NarExecutionBuilder builder = new NarExecutionBuilder(compileMojo, compileExecution); settings = builder.build(buildType); } catch (MojoFailureException e) { - throw new CoreException(new Status(IStatus.ERROR, - MavenNarPlugin.PLUGIN_ID, - "Couldn't configure mojo")); + throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Couldn't configure mojo")); } catch (MojoExecutionException e) { - throw new CoreException(new Status(IStatus.ERROR, - MavenNarPlugin.PLUGIN_ID, - "Couldn't configure mojo")); + throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Couldn't configure mojo")); } finally { - releaseMojo(maven, mavenProject, narMojo, compileExecution, - monitor); + releaseMojo(maven, mavenProject, narMojo, compileExecution, monitor); } } else { - throw new CoreException(new Status(IStatus.ERROR, - MavenNarPlugin.PLUGIN_ID, - "Couldn't find default-nar-compile execution")); + throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Couldn't find default-nar-compile execution")); } return settings; } - public static List getCompileExecutions( - final ConfiguratorContext context, - final IMavenProjectFacade facade, - final IProgressMonitor monitor) + public static List getCompileExecutions(final ConfiguratorContext context, final IMavenProjectFacade facade, final IProgressMonitor monitor) throws CoreException { return getExecutions(NAR_COMPILE_GOAL, context, facade, monitor); } - - public static List getTestCompileExecutions( - final ConfiguratorContext context, - final IMavenProjectFacade facade, - final IProgressMonitor monitor) - throws CoreException { + + public static List getTestCompileExecutions(final ConfiguratorContext context, final IMavenProjectFacade facade, + final IProgressMonitor monitor) throws CoreException { return getExecutions(NAR_TESTCOMPILE_GOAL, context, facade, monitor); } - - public static List getExecutions( - final String goal, - final ConfiguratorContext context, - final IMavenProjectFacade facade, - final IProgressMonitor monitor) - throws CoreException { + + public static List getExecutions(final String goal, final ConfiguratorContext context, final IMavenProjectFacade facade, + final IProgressMonitor monitor) throws CoreException { final List compileExecutions = new ArrayList(); final Map> configuratorExecutions = AbstractProjectConfigurator.getConfiguratorExecutions(facade); @@ -336,32 +264,30 @@ public static List getExecutions( return compileExecutions; } - public static List buildCompileNarExecutions(final ConfiguratorContext context, final IMavenProjectFacade facade, final IProgressMonitor monitor) throws CoreException { + public static List buildCompileNarExecutions(final ConfiguratorContext context, final IMavenProjectFacade facade, + final IProgressMonitor monitor) throws CoreException { List narExecutions = new ArrayList(); - List compileExecutions = MavenUtils - .getCompileExecutions(context, facade, monitor); + List compileExecutions = MavenUtils.getCompileExecutions(context, facade, monitor); for (MojoExecution compileExecution : compileExecutions) { - NarExecution narSettings = MavenUtils.readCompileSettings(context, - facade, compileExecution, monitor); + NarExecution narSettings = MavenUtils.readCompileSettings(context, facade, compileExecution, monitor); narExecutions.add(narSettings); } return narExecutions; } - public static List buildTestCompileNarExecutions(final ConfiguratorContext context, final IMavenProjectFacade facade, final IProgressMonitor monitor) throws CoreException { + public static List buildTestCompileNarExecutions(final ConfiguratorContext context, final IMavenProjectFacade facade, + final IProgressMonitor monitor) throws CoreException { List narExecutions = new ArrayList(); - List testCompileExecutions = MavenUtils - .getTestCompileExecutions(context, facade, monitor); + List testCompileExecutions = MavenUtils.getTestCompileExecutions(context, facade, monitor); for (MojoExecution testCompileExecution : testCompileExecutions) { - NarExecution narSettings = MavenUtils.readTestCompileSettings(context, - facade, testCompileExecution, monitor); + NarExecution narSettings = MavenUtils.readTestCompileSettings(context, facade, testCompileExecution, monitor); narExecutions.add(narSettings); } return narExecutions; } - + public static boolean isTestUnpack(String goal) { return NAR_TESTUNPACK_GOAL.equals(goal) || NAR_TEST_UNPACK_GOAL.equals(goal); } - + } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/Messages.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/Messages.java index e2b9083..8f3360a 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/Messages.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/Messages.java @@ -22,51 +22,51 @@ import org.eclipse.osgi.util.NLS; public class Messages extends NLS { - private static final String BUNDLE_NAME = "com.github.sdedwards.m2e_nar.internal.messages"; //$NON-NLS-1$ + private static final String BUNDLE_NAME = "com.github.sdedwards.m2e_nar.internal.messages"; //$NON-NLS-1$ - public static String CProjectConfigurator_task_name; + public static String CProjectConfigurator_task_name; - public static String BuildPathManager_setting_paths; + public static String BuildPathManager_setting_paths; - public static String DownloadSourcesJob_job_download; + public static String DownloadSourcesJob_job_download; - public static String MavenClasspathContainer_description; + public static String MavenClasspathContainer_description; - public static String MavenClasspathContainerInitializer_error_cannot_persist; + public static String MavenClasspathContainerInitializer_error_cannot_persist; - public static String MavenClasspathContainerInitializer_job_name; + public static String MavenClasspathContainerInitializer_job_name; - public static String MavenClasspathContainerPage_control_desc; + public static String MavenClasspathContainerPage_control_desc; - public static String MavenClasspathContainerPage_control_title; + public static String MavenClasspathContainerPage_control_title; - public static String MavenClasspathContainerPage_link; + public static String MavenClasspathContainerPage_link; - public static String MavenClasspathContainerPage_title; + public static String MavenClasspathContainerPage_title; - public static String MavenJdtPlugin_job_name; + public static String MavenJdtPlugin_job_name; - public static String MavenRuntimeClasspathProvider_error_unsupported; + public static String MavenRuntimeClasspathProvider_error_unsupported; - public static String OpenJavaDocAction_error_download; + public static String OpenJavaDocAction_error_download; - public static String OpenJavaDocAction_error_message; + public static String OpenJavaDocAction_error_message; - public static String OpenJavaDocAction_error_title; + public static String OpenJavaDocAction_error_title; - public static String OpenJavaDocAction_info_title; + public static String OpenJavaDocAction_info_title; - public static String OpenJavaDocAction_job_open_javadoc; + public static String OpenJavaDocAction_job_open_javadoc; - public static String OpenJavaDocAction_message1; + public static String OpenJavaDocAction_message1; - public static String CProjectConfigurator_error_configure_execution; - - static { - // initialize resource bundle - NLS.initializeMessages(BUNDLE_NAME, Messages.class); - } + public static String CProjectConfigurator_error_configure_execution; - private Messages() { - } + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/NarBuildParticipant.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/NarBuildParticipant.java index 8097a0f..ab1cce8 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/NarBuildParticipant.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/NarBuildParticipant.java @@ -34,30 +34,24 @@ public class NarBuildParticipant extends MojoExecutionBuildParticipant { private static final Logger logger = LoggerFactory.getLogger(CProjectConfigurator.class); - + public NarBuildParticipant(MojoExecution execution, boolean runOnIncremental, boolean runOnConfiguration) { super(execution, runOnIncremental, runOnConfiguration); } @Override - public Set build(int kind, IProgressMonitor monitor) - throws Exception { + public Set build(int kind, IProgressMonitor monitor) throws Exception { logger.info("Build kind=" + kind + " for execution " + getMojoExecution().getExecutionId()); Set retVal = null; if (appliesToBuildKind(kind)) { retVal = super.build(kind, monitor); MavenProject project = getMavenProjectFacade().getMavenProject(monitor); - File generated = MavenPlugin.getMaven().getMojoParameterValue(project, - getMojoExecution(), - "outputDirectory", - File.class, - monitor); + File generated = MavenPlugin.getMaven().getMojoParameterValue(project, getMojoExecution(), "outputDirectory", File.class, monitor); if (generated != null) { getBuildContext().refresh(generated); } } return retVal; } - - + } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/NarClassloader.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/NarClassloader.java index a547ec5..5eb90eb 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/NarClassloader.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/NarClassloader.java @@ -36,12 +36,12 @@ import com.github.sdedwards.m2e_nar.MavenNarPlugin; public class NarClassloader extends ClassLoader { - + private final String mavenPackage = "org.eclipse.m2e.cdt.internal.nar.maven"; private final String builder = "org.eclipse.m2e.cdt.internal.nar.maven.NarExecutionBuilder"; - + private ClassRealm mavenClassloader; - + public NarClassloader(ClassRealm mavenClassloader) { this.mavenClassloader = mavenClassloader; } @@ -51,12 +51,8 @@ public INarExecutionBuilder createNarExecutionBuilder(final MavenProject mavenPr Class clazz = Class.forName(builder, true, this); Constructor constructor = clazz.getConstructor(MavenProject.class, AbstractMojo.class); return (INarExecutionBuilder) constructor.newInstance(mavenProject, mojo); - } - catch (Exception e) { - throw new CoreException(new Status(IStatus.ERROR, - MavenNarPlugin.PLUGIN_ID, - "NAR Classloader problem", - e)); + } catch (Exception e) { + throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "NAR Classloader problem", e)); } } @@ -66,10 +62,9 @@ protected Class findClass(String name) throws ClassNotFoundException { // Try the parent classloader by default try { return NarClassloader.class.getClassLoader().loadClass(name); - } - catch (ClassNotFoundException e) { + } catch (ClassNotFoundException e) { // Now try the Maven plugin realm classloader - return mavenClassloader.loadClass(name); + return mavenClassloader.loadClass(name); } } // Find the class file in the bundle @@ -93,8 +88,7 @@ private Class readClass(final String name, final URL url) throws ClassNotFoun } byte[] buf = out.toByteArray(); return defineClass(name, buf, 0, buf.length); - } - catch (IOException e) { + } catch (IOException e) { throw new ClassNotFoundException(name + " cannot be loaded", e); } } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/NarExecutionBuilder.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/NarExecutionBuilder.java index cae2862..d6b2ddf 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/NarExecutionBuilder.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/NarExecutionBuilder.java @@ -55,15 +55,15 @@ public class NarExecutionBuilder implements INarExecutionBuilder { private static final Logger logger = LoggerFactory.getLogger(NarExecutionBuilder.class); private final INarCompileMojo narCompileMojo; private final MojoExecution mojoExecution; - + public NarExecutionBuilder(final AbstractMojo compileMojo, final MojoExecution mojoExceution) { this.narCompileMojo = (INarCompileMojo) compileMojo; this.mojoExecution = mojoExceution; } - + public NarExecution build(final String buildType) throws CoreException { try { - NarExecution settings = new NarExecution(mojoExecution); + NarExecution settings = new NarExecution(mojoExecution); settings.setSkip(narCompileMojo.isSkip()); settings.setOS(narCompileMojo.getOS()); settings.setLinkerName(narCompileMojo.getLinker().getName()); @@ -74,57 +74,47 @@ public NarExecution build(final String buildType) throws CoreException { ILibrary library = (ILibrary) iter.next(); NarBuildArtifact buildArtifact = buildArtifactSettings(library.getType(), buildType, library.linkCPP(), null); buildArtifact.setArtifactName(narCompileMojo.getOutput(library.getType())); - buildArtifact.setConfigName(CdtUtils.getConfigName( - mojoExecution, buildArtifact)); + buildArtifact.setConfigName(CdtUtils.getConfigName(mojoExecution, buildArtifact)); artifactSettings.add(buildArtifact); } - } - else if (NarExecution.TEST.equals(buildType)) { + } else if (NarExecution.TEST.equals(buildType)) { List tests = narCompileMojo.getTests(); for (Iterator iter = tests.iterator(); iter.hasNext();) { ITest test = (ITest) iter.next(); NarBuildArtifact buildArtifact = buildArtifactSettings(NarBuildArtifact.EXECUTABLE, buildType, true, test); buildArtifact.setArtifactName(test.getName()); - buildArtifact.setConfigName(CdtUtils.getTestConfigName( - mojoExecution, buildArtifact)); + buildArtifact.setConfigName(CdtUtils.getTestConfigName(mojoExecution, buildArtifact)); artifactSettings.add(buildArtifact); } } return settings; - } - catch (MojoFailureException e) { - throw new CoreException(new Status(IStatus.ERROR, - MavenNarPlugin.PLUGIN_ID, - "Mojo failure", - e)); - } - catch (MojoExecutionException e) { - throw new CoreException(new Status(IStatus.ERROR, - MavenNarPlugin.PLUGIN_ID, - "Mojo execution failed", - e)); + } catch (MojoFailureException e) { + throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Mojo failure", e)); + } catch (MojoExecutionException e) { + throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Mojo execution failed", e)); } } - + @SuppressWarnings("unchecked") - private NarBuildArtifact buildArtifactSettings(final String type, final String buildType, final boolean linkCPP, final ITest test) throws MojoExecutionException, MojoFailureException { + private NarBuildArtifact buildArtifactSettings(final String type, final String buildType, final boolean linkCPP, final ITest test) + throws MojoExecutionException, MojoFailureException { NarBuildArtifact settings = new NarBuildArtifact(); - + settings.setType(type); - + List projectRefs = settings.getProjectReferences(); List narArtifacts = narCompileMojo.getNarArtifacts(); for (com.github.maven_nar.NarArtifact artifact : narArtifacts) { if (artifact.getNarLayout() instanceof EclipseNarLayout) { - EclipseNarLayout layout = (EclipseNarLayout)artifact.getNarLayout(); + EclipseNarLayout layout = (EclipseNarLayout) artifact.getNarLayout(); projectRefs.add(layout.getProject().getProject().getName()); } } - + settings.setLinkerSettings(buildLinkerSettings(narCompileMojo.getLinker(), linkCPP)); settings.setCppSettings(buildCompilerSettings(narCompileMojo.getCpp(), buildType, test)); settings.setCSettings(buildCompilerSettings(narCompileMojo.getC(), buildType, test)); - + List javahIncludePaths = settings.getJavahIncludePaths(); javahIncludePaths.addAll(narCompileMojo.getJavahIncludePaths()); List javaIncludePaths = settings.getJavaIncludePaths(); @@ -134,16 +124,16 @@ private NarBuildArtifact buildArtifactSettings(final String type, final String b dependencyIncludePaths.addAll(narCompileMojo.getDependencyIncludePaths()); List dependencyLibs = settings.getDependencyLibs(); logger.debug("library size " + narCompileMojo.getDependencyLibs(type, test).size()); - for (Iterator it = narCompileMojo.getDependencyLibs(type, test).iterator(); it.hasNext(); ) { + for (Iterator it = narCompileMojo.getDependencyLibs(type, test).iterator(); it.hasNext();) { dependencyLibs.add(buildLibSettings((ILib) it.next())); } List dependencySysLibs = settings.getDependencySysLibs(); - for (Iterator it = narCompileMojo.getDependencySysLibs(type).iterator(); it.hasNext(); ) { + for (Iterator it = narCompileMojo.getDependencySysLibs(type).iterator(); it.hasNext();) { dependencySysLibs.add(buildSysLibSettings((ISysLib) it.next())); } List dependencyOptions = settings.getDependencyOptions(); dependencyOptions.addAll(narCompileMojo.getDependencyOptions(type)); - + return settings; } @@ -152,13 +142,13 @@ public NarLinker buildLinkerSettings(final ILinker linker, final boolean linkCpp NarLinker settings = new NarLinker(); settings.setName(linker.getName()); List libs = settings.getLibs(); - for (Iterator it = linker.getLibs().iterator(); it.hasNext(); ) { + for (Iterator it = linker.getLibs().iterator(); it.hasNext();) { libs.add(buildLibSettings((ILib) it.next())); } List sysLibs = settings.getSysLibs(); - for (Iterator it = linker.getSysLibs().iterator(); it.hasNext(); ) { + for (Iterator it = linker.getSysLibs().iterator(); it.hasNext();) { sysLibs.add(buildSysLibSettings((ISysLib) it.next())); - } + } settings.setIncremental(linker.isIncremental()); settings.setMap(linker.isMap()); List options = settings.getOptions(); @@ -168,12 +158,13 @@ public NarLinker buildLinkerSettings(final ILinker linker, final boolean linkCpp } @SuppressWarnings("unchecked") - private NarCompiler buildCompilerSettings(final ICompiler compiler, final String buildType, final ITest test) throws MojoFailureException, MojoExecutionException { + private NarCompiler buildCompilerSettings(final ICompiler compiler, final String buildType, final ITest test) throws MojoFailureException, + MojoExecutionException { NarCompiler settings = new NarCompiler(); settings.setName(compiler.getName()); List includePaths = settings.getIncludePaths(); includePaths.addAll(compiler.getIncludePaths(buildType)); - + List systemIncludes = compiler.getSystemIncludePaths(); if (systemIncludes != null) { List systemIncludePaths = settings.getSystemIncludePaths(); @@ -181,7 +172,7 @@ private NarCompiler buildCompilerSettings(final ICompiler compiler, final String } List sourceDirectories = settings.getSourceDirectories(); sourceDirectories.addAll(compiler.getSourceDirectories(buildType)); - + settings.setDebug(compiler.isDebug()); settings.setRtti(compiler.isRtti()); settings.setOptimize(NarCompiler.OptimizationLevel.valueOf(compiler.getOptimize().toUpperCase())); @@ -195,21 +186,21 @@ private NarCompiler buildCompilerSettings(final ICompiler compiler, final String options.addAll(compiler.getOptions()); Set includes = settings.getIncludes(); for (Object include : compiler.getIncludes(buildType)) { - String includeStr = (String)include; + String includeStr = (String) include; if (includeStr.trim().length() > 0) { includes.add(includeStr); } } Set excludes = settings.getExcludes(); for (Object exclude : compiler.getExcludes(buildType, test)) { - String excludeStr = (String)exclude; + String excludeStr = (String) exclude; if (excludeStr.trim().length() > 0) { excludes.add(excludeStr); } } return settings; } - + public NarLib buildLibSettings(final ILib lib) { logger.debug("NAR library: " + lib.getName()); NarLib settings = new NarLib(); @@ -218,7 +209,7 @@ public NarLib buildLibSettings(final ILib lib) { settings.setDirectory(lib.getDirectory()); return settings; } - + public NarSysLib buildSysLibSettings(final ISysLib syslib) { logger.debug("NAR sys library: " + syslib.getName()); NarSysLib settings = new NarSysLib(); diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/NarTestCompileBuildParticipant.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/NarTestCompileBuildParticipant.java index c969812..bc7a76b 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/NarTestCompileBuildParticipant.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/NarTestCompileBuildParticipant.java @@ -27,14 +27,13 @@ public class NarTestCompileBuildParticipant extends NarBuildParticipant { private static final Logger logger = LoggerFactory.getLogger(CProjectConfigurator.class); - + public NarTestCompileBuildParticipant(MojoExecution execution, boolean runOnIncremental, boolean runOnConfiguration) { - super(new MojoExecution(execution.getMojoDescriptor(), execution.getExecutionId(), execution.getSource()) - , runOnIncremental, runOnConfiguration); + super(new MojoExecution(execution.getMojoDescriptor(), execution.getExecutionId(), execution.getSource()), runOnIncremental, runOnConfiguration); // Some versions of nar-maven-plugin don't have a nar-test-unpack goal // this means the test artifacts won't be available to us. - // What we need to do is run the nar-testCompile goal without any tests its configuration - // in order to just unpack. + // What we need to do is run the nar-testCompile goal without any tests + // its configuration in order to just unpack. Xpp3Dom configuration = new Xpp3Dom(execution.getConfiguration()); logger.info("Configuration before: " + configuration); for (int i = 0; i < configuration.getChildCount(); ++i) { diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/AbstractGnuCompilerSynchroniser.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/AbstractGnuCompilerSynchroniser.java index 580de8d..2e6f8e9 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/AbstractGnuCompilerSynchroniser.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/AbstractGnuCompilerSynchroniser.java @@ -33,39 +33,32 @@ @SuppressWarnings("restriction") public abstract class AbstractGnuCompilerSynchroniser implements SettingsSynchroniser { - + private static final String defaultFlags = "-c"; private static final boolean isPICMeaningful = System.getProperty("os.name").indexOf("Windows") < 0; private static final String noExceptions = "-fno-exceptions"; protected enum GnuOptimizationLevel { - NONE, - OPTIMIZE, - MORE, - MOST, - SIZE + NONE, OPTIMIZE, MORE, MOST, SIZE } protected enum GnuDebugLevel { - NONE, - MINIMAL, - DEFAULT, - MAX + NONE, MINIMAL, DEFAULT, MAX } public AbstractGnuCompilerSynchroniser() { } public abstract NarCompiler getCompilerSettings(NarBuildArtifact settings); - + public abstract String getToolId(); - + public abstract String getUndefOptionId(); public abstract String getOptLevelOptionId(); - + public abstract String getOptLevel(GnuOptimizationLevel optLevel); - + public abstract String getDebugLevelOptionId(); public abstract String getDebugLevel(GnuDebugLevel debugLevel); @@ -73,50 +66,48 @@ public AbstractGnuCompilerSynchroniser() { public abstract String getOtherFlagsOptionId(); public abstract String getFPICOptionId(); - + public String getFlags(final NarCompiler compilerSettings) { final StringBuilder flags = new StringBuilder(); - + flags.append(defaultFlags); for (String option : compilerSettings.getOptions()) { flags.append(" "); flags.append(option); } - + // Add no exceptions flag if required if (!compilerSettings.isExceptions()) { flags.append(" "); flags.append(noExceptions); } - + return flags.toString(); } @Override - public void fullSync(ICConfigurationDescription cfg, - NarBuildArtifact artifactSettings) throws CoreException { - BuildConfigurationData confData = (BuildConfigurationData)cfg.getConfigurationData(); + public void fullSync(ICConfigurationDescription cfg, NarBuildArtifact artifactSettings) throws CoreException { + BuildConfigurationData confData = (BuildConfigurationData) cfg.getConfigurationData(); IConfiguration managedConf = confData.getConfiguration(); for (final ITool tool : managedConf.getToolsBySuperClassId(getToolId())) { tool.setToolCommand(getCompilerSettings(artifactSettings).getName()); - } + } final OptionSetter optionSetter = new OptionSetter(managedConf, getToolId()); setUndefinedSymbols(optionSetter, artifactSettings); setOptimization(optionSetter, artifactSettings); setDebug(optionSetter, artifactSettings); - setOptions(optionSetter, artifactSettings); + setOptions(optionSetter, artifactSettings); } @Override - public void pathsOnlySync(ICConfigurationDescription cfg, - NarBuildArtifact artifactSettings) throws CoreException { + public void pathsOnlySync(ICConfigurationDescription cfg, NarBuildArtifact artifactSettings) throws CoreException { } - + protected void setUndefinedSymbols(final OptionSetter optionSetter, final NarBuildArtifact settings) throws CoreException { List undefines = getCompilerSettings(settings).getUndefines(); String[] undefineArray = undefines.toArray(new String[undefines.size()]); - + optionSetter.setOption(getUndefOptionId(), undefineArray); } @@ -147,7 +138,7 @@ protected void setOptimization(final OptionSetter optionSetter, final NarBuildAr break; case UNSAFE: levelGcc = GnuOptimizationLevel.MOST; - break; + break; } optionSetter.setOption(getOptLevelOptionId(), getOptLevel(levelGcc)); } @@ -158,15 +149,15 @@ protected void setDebug(final OptionSetter optionSetter, final NarBuildArtifact optionSetter.setOption(getDebugLevelOptionId(), getDebugLevel(debugLevel)); } - + protected void setOptions(final OptionSetter optionSetter, final NarBuildArtifact settings) throws CoreException { // Clear all other options optionSetter.clearOptions(); - + // Get the flags String flags = getFlags(getCompilerSettings(settings)); optionSetter.setOption(getOtherFlagsOptionId(), flags.trim()); - + // Set fPIC option if required if (isPICMeaningful && settings.isSharedLibrary()) { optionSetter.setOption(getFPICOptionId(), true); diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/AbstractGnuLinkerSynchroniser.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/AbstractGnuLinkerSynchroniser.java index 20aa975..5243c85 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/AbstractGnuLinkerSynchroniser.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/AbstractGnuLinkerSynchroniser.java @@ -34,21 +34,21 @@ @SuppressWarnings("restriction") public abstract class AbstractGnuLinkerSynchroniser implements SettingsSynchroniser { - + private static final String defaultFlags = ""; private static final String rpathFlag = "-Wl,-rpath"; private static final String incrementalFlag = "-i"; private static final String mapFlag = "-M"; - + public AbstractGnuLinkerSynchroniser() { } public abstract String getToolId(); - + public abstract String getFlagsOptionId(); - + public abstract String getSharedOptionId(); - + public String getFlags(final NarLinker linkerSettings, final List libs) { final StringBuilder flags = new StringBuilder(); @@ -73,36 +73,33 @@ public String getFlags(final NarLinker linkerSettings, final List libs) if (first) { first = false; flags.append(" " + rpathFlag + ","); - } - else { + } else { flags.append(":"); } flags.append(lib.getDirectory()); } return flags.toString(); } - + @Override - public void fullSync(ICConfigurationDescription cfg, - NarBuildArtifact artifactSettings) throws CoreException { - final BuildConfigurationData confData = (BuildConfigurationData)cfg.getConfigurationData(); + public void fullSync(ICConfigurationDescription cfg, NarBuildArtifact artifactSettings) throws CoreException { + final BuildConfigurationData confData = (BuildConfigurationData) cfg.getConfigurationData(); final IConfiguration managedConf = confData.getConfiguration(); for (final ITool tool : managedConf.getToolsBySuperClassId(getToolId())) { tool.setToolCommand(artifactSettings.getLinkerSettings().getName()); - } + } } @Override - public void pathsOnlySync(ICConfigurationDescription cfg, - NarBuildArtifact artifactSettings) throws CoreException { - final BuildConfigurationData confData = (BuildConfigurationData)cfg.getConfigurationData(); + public void pathsOnlySync(ICConfigurationDescription cfg, NarBuildArtifact artifactSettings) throws CoreException { + final BuildConfigurationData confData = (BuildConfigurationData) cfg.getConfigurationData(); final IConfiguration managedConf = confData.getConfiguration(); final OptionSetter optionSetter = new OptionSetter(managedConf, getToolId()); - setOptions(optionSetter, artifactSettings); + setOptions(optionSetter, artifactSettings); } - + protected void setOptions(final OptionSetter optionSetter, final NarBuildArtifact settings) throws CoreException { - + // Clear all other options optionSetter.clearOptions(); @@ -113,7 +110,7 @@ protected void setOptions(final OptionSetter optionSetter, final NarBuildArtifac } String flags = getFlags(settings.getLinkerSettings(), libs); optionSetter.setOption(getFlagsOptionId(), flags.trim()); - + if (settings.isSharedLibrary()) { // Add the shared flag optionSetter.setOption(getSharedOptionId(), true); diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/AbstractSettingsSynchroniser.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/AbstractSettingsSynchroniser.java index a3a9b93..28382f2 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/AbstractSettingsSynchroniser.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/AbstractSettingsSynchroniser.java @@ -60,14 +60,14 @@ public abstract class AbstractSettingsSynchroniser implements SettingsSynchronis protected static final String cppLanguageId = "org.eclipse.cdt.core.g++"; protected static final String cLanguageId = "org.eclipse.cdt.core.gcc"; - //protected String cppSourceContentType = "org.eclipse.cdt.core.cxxSource"; - //protected String cSourceContentType = "org.eclipse.cdt.core.cSource"; - + // protected String cppSourceContentType = "org.eclipse.cdt.core.cxxSource"; + // protected String cSourceContentType = "org.eclipse.cdt.core.cSource"; + private final List toolSpecifics = new ArrayList(); public AbstractSettingsSynchroniser() { } - + protected void addToolSpecificSynchroniser(SettingsSynchroniser toolSpecificSynchroniser) { toolSpecifics.add(toolSpecificSynchroniser); } @@ -85,12 +85,11 @@ public void fullSync(final ICConfigurationDescription cfg, final NarBuildArtifac toolSpecificSynchroniser.fullSync(cfg, artifactSettings); } } - - private void setArtifactName(ICConfigurationDescription cfg, - NarBuildArtifact artifactSettings) { + + private void setArtifactName(ICConfigurationDescription cfg, NarBuildArtifact artifactSettings) { final String artifactName = artifactSettings.getArtifactName(); if (artifactName != null) { - BuildConfigurationData confData = (BuildConfigurationData)cfg.getConfigurationData(); + BuildConfigurationData confData = (BuildConfigurationData) cfg.getConfigurationData(); IConfiguration managedConf = confData.getConfiguration(); managedConf.setArtifactName(artifactName); } @@ -101,16 +100,16 @@ public void pathsOnlySync(final ICConfigurationDescription cfg, final NarBuildAr logger.info("Paths sync to configuration " + cfg.getName()); setProjectRefs(cfg, artifactSettings); setIncludes(cfg, artifactSettings); - setLibraryPaths(cfg, artifactSettings); + setLibraryPaths(cfg, artifactSettings); setLibraries(cfg, artifactSettings); // Tool-specific settings for (SettingsSynchroniser toolSpecificSynchroniser : toolSpecifics) { toolSpecificSynchroniser.pathsOnlySync(cfg, artifactSettings); } } - + public abstract String getToolchain(); - + private void setProjectRefs(final ICConfigurationDescription conf, final NarBuildArtifact settings) throws CoreException { Map refs = new HashMap(); for (String projectName : settings.getProjectReferences()) { @@ -160,39 +159,37 @@ private void setIncludes(final ICConfigurationDescription conf, final NarBuildAr l.addAll(commonIncludePathEntries); if (cppLanguageId.equals(setting.getLanguageId())) { l.addAll(cppIncludePathEntries); - } - else if (cLanguageId.equals(setting.getLanguageId())) { + } else if (cLanguageId.equals(setting.getLanguageId())) { l.addAll(cIncludePathEntries); } setting.setSettingEntries(ICSettingEntry.INCLUDE_PATH, l); } } - + private void setDefinedSymbols(final ICConfigurationDescription conf, final NarBuildArtifact settings) throws CoreException { final ICLanguageSetting[] languageSettings = conf.getRootFolderDescription().getLanguageSettings(); final List cMacroEntries = new ArrayList(); for (final String define : settings.getCSettings().getDefines()) { ICMacroEntry macroEntry = createMacroEntry(define, 0); - cMacroEntries.add(macroEntry); + cMacroEntries.add(macroEntry); } final List cppMacroEntries = new ArrayList(); for (final String define : settings.getCppSettings().getDefines()) { ICMacroEntry macroEntry = createMacroEntry(define, 0); - cppMacroEntries.add(macroEntry); + cppMacroEntries.add(macroEntry); } for (ICLanguageSetting setting : languageSettings) { final List l = setting.getSettingEntriesList(ICSettingEntry.MACRO); l.clear(); if (cppLanguageId.equals(setting.getLanguageId())) { l.addAll(cppMacroEntries); - } - else if (cLanguageId.equals(setting.getLanguageId())) { + } else if (cLanguageId.equals(setting.getLanguageId())) { l.addAll(cMacroEntries); } setting.setSettingEntries(ICSettingEntry.MACRO, l); } - + } private void setSourceDirs(final ICConfigurationDescription conf, final NarBuildArtifact settings) throws CoreException { @@ -211,10 +208,10 @@ private void setSourceDirs(final ICConfigurationDescription conf, final NarBuild } conf.setSourceEntries(sourceEntries); } - + private void setLibraryPaths(final ICConfigurationDescription conf, final NarBuildArtifact settings) throws CoreException { final ICLanguageSetting[] languageSettings = conf.getRootFolderDescription().getLanguageSettings(); - + final List libraryPathEntries = new ArrayList(); for (final NarLib lib : settings.getDependencyLibs()) { ICLibraryPathEntry libraryPath = createLibraryPathEntry(lib.getDirectory().getPath(), 0); @@ -229,12 +226,12 @@ private void setLibraryPaths(final ICConfigurationDescription conf, final NarBui l.clear(); l.addAll(libraryPathEntries); setting.setSettingEntries(ICSettingEntry.LIBRARY_PATH, l); - } + } } - + private void setLibraries(final ICConfigurationDescription conf, final NarBuildArtifact settings) throws CoreException { final ICLanguageSetting[] languageSettings = conf.getRootFolderDescription().getLanguageSettings(); - + final List libraryEntries = new ArrayList(); for (final NarLib lib : settings.getDependencyLibs()) { final ICLibraryFileEntry library = CDataUtil.createCLibraryFileEntry(lib.getName(), 0); @@ -253,42 +250,39 @@ private void setLibraries(final ICConfigurationDescription conf, final NarBuildA libraryEntries.add(library); } /* - for (String path : settings.getLibraries()) { - ICLibraryFileEntry library = CDataUtil.createCLibraryFileEntry(lib, 0); - libraryPathEntries.add(library); - } - */ + * for (String path : settings.getLibraries()) { ICLibraryFileEntry + * library = CDataUtil.createCLibraryFileEntry(lib, 0); + * libraryPathEntries.add(library); } + */ for (final ICLanguageSetting setting : languageSettings) { final List l = setting.getSettingEntriesList(ICSettingEntry.LIBRARY_FILE); l.clear(); l.addAll(libraryEntries); setting.setSettingEntries(ICSettingEntry.LIBRARY_FILE, l); - } + } } - + private ICIncludePathEntry createIncludePathEntry(final String path, final int flags) { final IWorkspaceRoot workspace = ResourcesPlugin.getWorkspace().getRoot(); final File file = new File(path); logger.debug("Include path " + path); if (!file.isAbsolute()) { return CDataUtil.createCIncludePathEntry(path, ICSettingEntry.VALUE_WORKSPACE_PATH | flags); - } - else { + } else { IContainer container = workspace.getContainerForLocation(Path.fromOSString(path)); if (container == null) { return CDataUtil.createCIncludePathEntry(path, flags); - } - else { + } else { return CDataUtil.createCIncludePathEntry(container.getFullPath().toOSString(), ICSettingEntry.VALUE_WORKSPACE_PATH | flags); - } + } } } - + private ICMacroEntry createMacroEntry(final String define, final int flags) { final String[] split = define.split("=", 2); return CDataUtil.createCMacroEntry(split[0], (split.length > 1 ? split[1] : null), flags); } - + private ICSourceEntry createSourcePathEntry(final String path, final Set excludes, final int flags) { IPath[] exclusionPatterns = null; if (excludes.size() > 0) { @@ -303,15 +297,15 @@ private ICSourceEntry createSourcePathEntry(final String path, final Set final IWorkspaceRoot workspace = ResourcesPlugin.getWorkspace().getRoot(); final File file = new File(path); if (!file.isAbsolute()) { - return (ICSourceEntry)CDataUtil.createEntry(ICLanguageSettingEntry.SOURCE_PATH, path, null, exclusionPatterns, ICSettingEntry.VALUE_WORKSPACE_PATH | flags); - } - else { + return (ICSourceEntry) CDataUtil.createEntry(ICLanguageSettingEntry.SOURCE_PATH, path, null, exclusionPatterns, ICSettingEntry.VALUE_WORKSPACE_PATH + | flags); + } else { IContainer container = workspace.getContainerForLocation(Path.fromOSString(path)); if (container == null) { - return (ICSourceEntry)CDataUtil.createEntry(ICLanguageSettingEntry.SOURCE_PATH, path, null, exclusionPatterns, flags); - } - else { - return (ICSourceEntry)CDataUtil.createEntry(ICLanguageSettingEntry.SOURCE_PATH, container.getFullPath().toOSString(), null, exclusionPatterns, ICSettingEntry.VALUE_WORKSPACE_PATH | flags); + return (ICSourceEntry) CDataUtil.createEntry(ICLanguageSettingEntry.SOURCE_PATH, path, null, exclusionPatterns, flags); + } else { + return (ICSourceEntry) CDataUtil.createEntry(ICLanguageSettingEntry.SOURCE_PATH, container.getFullPath().toOSString(), null, exclusionPatterns, + ICSettingEntry.VALUE_WORKSPACE_PATH | flags); } } } @@ -321,15 +315,13 @@ private ICLibraryPathEntry createLibraryPathEntry(final String path, final int f final File file = new File(path); if (!file.isAbsolute()) { return CDataUtil.createCLibraryPathEntry(path, ICSettingEntry.VALUE_WORKSPACE_PATH | flags); - } - else { + } else { IContainer container = workspace.getContainerForLocation(Path.fromOSString(path)); if (container == null) { return CDataUtil.createCLibraryPathEntry(path, flags); - } - else { + } else { return CDataUtil.createCLibraryPathEntry(container.getFullPath().toOSString(), ICSettingEntry.VALUE_WORKSPACE_PATH | flags); - } + } } } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/CLinuxGccSynchroniser.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/CLinuxGccSynchroniser.java index d3354a0..a9571c4 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/CLinuxGccSynchroniser.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/CLinuxGccSynchroniser.java @@ -19,10 +19,8 @@ */ package com.github.sdedwards.m2e_nar.internal.cdt; - - public class CLinuxGccSynchroniser extends AbstractSettingsSynchroniser { - + protected static final String toolchain = "Linux GCC"; public CLinuxGccSynchroniser() { @@ -33,5 +31,5 @@ public CLinuxGccSynchroniser() { public String getToolchain() { return toolchain; } - + } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/CMacosxGccSynchroniser.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/CMacosxGccSynchroniser.java index 9929b4c..d0f11e1 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/CMacosxGccSynchroniser.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/CMacosxGccSynchroniser.java @@ -19,10 +19,8 @@ */ package com.github.sdedwards.m2e_nar.internal.cdt; - - public class CMacosxGccSynchroniser extends AbstractSettingsSynchroniser { - + protected static final String toolchain = "MacOSX GCC"; public CMacosxGccSynchroniser() { @@ -33,5 +31,5 @@ public CMacosxGccSynchroniser() { public String getToolchain() { return toolchain; } - + } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/CdtUtils.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/CdtUtils.java index f1734b9..fafff58 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/CdtUtils.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/CdtUtils.java @@ -28,8 +28,11 @@ public final class CdtUtils { public static final String DEFAULT_CONFIG_NAME_PREFIX = "nar-"; public static final String DEFAULT_TEST_CONFIG_NAME_PREFIX = "nar-test-"; - //private static final String DEFAULT_NAR_COMPILE_EXECUTION = "default-nar-compile"; - //private static final String DEFAULT_NAR_TESTCOMPILE_EXECUTION = "default-nar-testCompile"; + + // private static final String DEFAULT_NAR_COMPILE_EXECUTION = + // "default-nar-compile"; + // private static final String DEFAULT_NAR_TESTCOMPILE_EXECUTION = + // "default-nar-testCompile"; public static String convertArtefactType(final String narArtefactType) { if (NarBuildArtifact.EXECUTABLE.equals(narArtefactType)) { @@ -43,26 +46,24 @@ public static String convertArtefactType(final String narArtefactType) { } return ManagedBuildManager.BUILD_ARTEFACT_TYPE_PROPERTY_SHAREDLIB; } - + public static String getConfigName(MojoExecution compileExecution, NarBuildArtifact artifactSettings) { String configNamePrefix = DEFAULT_CONFIG_NAME_PREFIX; /* - if (!DEFAULT_NAR_COMPILE_EXECUTION.equals(compileExecution - .getExecutionId())) { - configNamePrefix = compileExecution.getExecutionId() + "-"; - } - */ + * if (!DEFAULT_NAR_COMPILE_EXECUTION.equals(compileExecution + * .getExecutionId())) { configNamePrefix = + * compileExecution.getExecutionId() + "-"; } + */ return configNamePrefix + artifactSettings.getType(); } public static String getTestConfigName(MojoExecution compileExecution, NarBuildArtifact artifactSettings) { String configNamePrefix = DEFAULT_TEST_CONFIG_NAME_PREFIX; /* - if (!DEFAULT_NAR_TESTCOMPILE_EXECUTION.equals(compileExecution - .getExecutionId())) { - configNamePrefix = compileExecution.getExecutionId() + "-"; - } - */ + * if (!DEFAULT_NAR_TESTCOMPILE_EXECUTION.equals(compileExecution + * .getExecutionId())) { configNamePrefix = + * compileExecution.getExecutionId() + "-"; } + */ return configNamePrefix + artifactSettings.getArtifactName(); } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/CppLinuxGccSynchroniser.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/CppLinuxGccSynchroniser.java index 7e051d5..5074dcc 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/CppLinuxGccSynchroniser.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/CppLinuxGccSynchroniser.java @@ -19,10 +19,8 @@ */ package com.github.sdedwards.m2e_nar.internal.cdt; - - public class CppLinuxGccSynchroniser extends AbstractSettingsSynchroniser { - + protected static final String toolchain = "Linux GCC"; public CppLinuxGccSynchroniser() { @@ -34,5 +32,5 @@ public CppLinuxGccSynchroniser() { public String getToolchain() { return toolchain; } - + } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/CppMacosxGccSynchroniser.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/CppMacosxGccSynchroniser.java index 9fad7f3..3247ce7 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/CppMacosxGccSynchroniser.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/CppMacosxGccSynchroniser.java @@ -19,10 +19,8 @@ */ package com.github.sdedwards.m2e_nar.internal.cdt; - - public class CppMacosxGccSynchroniser extends AbstractSettingsSynchroniser { - + protected static final String toolchain = "MacOSX GCC"; public CppMacosxGccSynchroniser() { @@ -34,5 +32,5 @@ public CppMacosxGccSynchroniser() { public String getToolchain() { return toolchain; } - + } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/GnuCCompilerSynchroniser.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/GnuCCompilerSynchroniser.java index d729685..5c30b94 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/GnuCCompilerSynchroniser.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/GnuCCompilerSynchroniser.java @@ -23,44 +23,38 @@ import com.github.sdedwards.m2e_nar.internal.model.NarCompiler; public class GnuCCompilerSynchroniser extends AbstractGnuCompilerSynchroniser { - + protected static final String cCompilerId = "cdt.managedbuild.tool.gnu.c.compiler"; protected static final String cOptLevel = "gnu.c.compiler.option.optimization.level"; protected static final String cDebugLevel = "gnu.c.compiler.option.debugging.level"; protected static final String cUndefId = "gnu.c.compiler.option.preprocessor.undef.symbol"; protected static final String cOtherFlags = "gnu.c.compiler.option.misc.other"; protected static final String cfPIC = "gnu.c.compiler.option.misc.pic"; - + protected enum COptimizationLevel { - NONE("gnu.c.optimization.level.none"), - OPTIMIZE("gnu.c.optimization.level.optimize"), - MORE("gnu.c.optimization.level.more"), - MOST("gnu.c.optimization.level.most"), - SIZE("gnu.c.optimization.level.size"); - + NONE("gnu.c.optimization.level.none"), OPTIMIZE("gnu.c.optimization.level.optimize"), MORE("gnu.c.optimization.level.more"), MOST( + "gnu.c.optimization.level.most"), SIZE("gnu.c.optimization.level.size"); + final String level; - + private COptimizationLevel(final String level) { this.level = level; } - + public String toString() { return level; } } - + protected enum CDebugLevel { - NONE("gnu.c.debugging.level.none"), - MINIMAL("gnu.c.debugging.level.minimal"), - DEFAULT("gnu.c.debugging.level.default"), - MAX("gnu.c.debugging.level.max"); - + NONE("gnu.c.debugging.level.none"), MINIMAL("gnu.c.debugging.level.minimal"), DEFAULT("gnu.c.debugging.level.default"), MAX("gnu.c.debugging.level.max"); + final String level; - + private CDebugLevel(final String level) { this.level = level; } - + public String toString() { return level; } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/GnuCLinkerSynchroniser.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/GnuCLinkerSynchroniser.java index ca4673c..003daa3 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/GnuCLinkerSynchroniser.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/GnuCLinkerSynchroniser.java @@ -19,14 +19,12 @@ */ package com.github.sdedwards.m2e_nar.internal.cdt; - - public class GnuCLinkerSynchroniser extends AbstractGnuLinkerSynchroniser { - + protected static final String cLinkerId = "cdt.managedbuild.tool.gnu.c.linker"; protected static final String cLdFlags = "gnu.c.link.option.flags"; protected static final String cShared = "gnu.c.link.option.shared"; - + public GnuCLinkerSynchroniser() { } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/GnuCppCompilerSynchroniser.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/GnuCppCompilerSynchroniser.java index 5dac5b9..6a7138f 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/GnuCppCompilerSynchroniser.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/GnuCppCompilerSynchroniser.java @@ -23,7 +23,7 @@ import com.github.sdedwards.m2e_nar.internal.model.NarCompiler; public class GnuCppCompilerSynchroniser extends AbstractGnuCompilerSynchroniser { - + protected static final String cppCompilerId = "cdt.managedbuild.tool.gnu.cpp.compiler"; protected static final String cppUndefId = "gnu.cpp.compiler.option.preprocessor.undef"; protected static final String cppOptLevel = "gnu.cpp.compiler.option.optimization.level"; @@ -32,37 +32,32 @@ public class GnuCppCompilerSynchroniser extends AbstractGnuCompilerSynchroniser protected static final String cppfPIC = "gnu.cpp.compiler.option.other.pic"; private static final String noRtti = "-fno-rtti"; - + protected enum CppOptimizationLevel { - NONE("gnu.cpp.compiler.optimization.level.none"), - OPTIMIZE("gnu.cpp.compiler.optimization.level.optimize"), - MORE("gnu.cpp.compiler.optimization.level.more"), - MOST("gnu.cpp.compiler.optimization.level.most"), - SIZE("gnu.cpp.compiler.optimization.level.size"); - + NONE("gnu.cpp.compiler.optimization.level.none"), OPTIMIZE("gnu.cpp.compiler.optimization.level.optimize"), MORE( + "gnu.cpp.compiler.optimization.level.more"), MOST("gnu.cpp.compiler.optimization.level.most"), SIZE("gnu.cpp.compiler.optimization.level.size"); + final String level; - + private CppOptimizationLevel(final String level) { this.level = level; } - + public String toString() { return level; } } protected enum CppDebugLevel { - NONE("gnu.cpp.compiler.debugging.level.none"), - MINIMAL("gnu.cpp.compiler.debugging.level.minimal"), - DEFAULT("gnu.cpp.compiler.debugging.level.default"), - MAX("gnu.cpp.compiler.debugging.level.max"); - + NONE("gnu.cpp.compiler.debugging.level.none"), MINIMAL("gnu.cpp.compiler.debugging.level.minimal"), DEFAULT("gnu.cpp.compiler.debugging.level.default"), MAX( + "gnu.cpp.compiler.debugging.level.max"); + final String level; - + private CppDebugLevel(final String level) { this.level = level; } - + public String toString() { return level; } @@ -139,7 +134,7 @@ public String getOtherFlagsOptionId() { public String getFPICOptionId() { return cppfPIC; } - + @Override public String getFlags(final NarCompiler compilerSettings) { final String flags = super.getFlags(compilerSettings); diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/GnuCppLinkerSynchroniser.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/GnuCppLinkerSynchroniser.java index 92b14fb..4943dcf 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/GnuCppLinkerSynchroniser.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/GnuCppLinkerSynchroniser.java @@ -19,14 +19,12 @@ */ package com.github.sdedwards.m2e_nar.internal.cdt; - - public class GnuCppLinkerSynchroniser extends AbstractGnuLinkerSynchroniser { - + protected static final String cppLinkerId = "cdt.managedbuild.tool.gnu.cpp.linker"; protected static final String cppLdFlags = "gnu.cpp.link.option.flags"; protected static final String cppShared = "gnu.cpp.link.option.shared"; - + public GnuCppLinkerSynchroniser() { } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/MacosxCLinkerSynchroniser.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/MacosxCLinkerSynchroniser.java index 9f5114d..04885e6 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/MacosxCLinkerSynchroniser.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/MacosxCLinkerSynchroniser.java @@ -19,14 +19,12 @@ */ package com.github.sdedwards.m2e_nar.internal.cdt; - - public class MacosxCLinkerSynchroniser extends AbstractGnuLinkerSynchroniser { - + protected static final String cLinkerId = "cdt.managedbuild.tool.macosx.c.linker"; protected static final String cLdFlags = "macosx.c.link.option.ldflags"; protected static final String cShared = "macosx.c.link.option.shared"; - + public MacosxCLinkerSynchroniser() { } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/MacosxCppLinkerSynchroniser.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/MacosxCppLinkerSynchroniser.java index df8baa4..189ce82 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/MacosxCppLinkerSynchroniser.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/MacosxCppLinkerSynchroniser.java @@ -19,14 +19,12 @@ */ package com.github.sdedwards.m2e_nar.internal.cdt; - - public class MacosxCppLinkerSynchroniser extends AbstractGnuLinkerSynchroniser { - + protected static final String cppLinkerId = "cdt.managedbuild.tool.macosx.cpp.linker"; protected static final String cppLdFlags = "macosx.cpp.link.option.flags"; protected static final String cppShared = "macosx.cpp.link.option.shared"; - + public MacosxCppLinkerSynchroniser() { } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/OptionSetter.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/OptionSetter.java index e9de4bd..ca8559e 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/OptionSetter.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/OptionSetter.java @@ -32,7 +32,7 @@ public final class OptionSetter { private final IConfiguration config; private final String toolId; - + public OptionSetter(final IConfiguration config, final String toolId) { this.config = config; this.toolId = toolId; @@ -47,31 +47,25 @@ public void clearOptions() throws CoreException { config.setOption(tool, option, false); break; case IOption.STRING: - config.setOption(tool, option, (String)null); + config.setOption(tool, option, (String) null); break; } } } - } - catch (BuildException e) { - throw new CoreException(new Status(IStatus.ERROR, - MavenNarPlugin.PLUGIN_ID, - "Couldn't clear options", e)); + } catch (BuildException e) { + throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Couldn't clear options", e)); } } - + public void setOption(final String optionId, final String value) throws CoreException { try { for (final ITool tool : config.getToolsBySuperClassId(toolId)) { final IOption option = tool.getOptionBySuperClassId(optionId); config.setOption(tool, option, value); } + } catch (BuildException e) { + throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Couldn't set " + optionId + " option", e)); } - catch (BuildException e) { - throw new CoreException(new Status(IStatus.ERROR, - MavenNarPlugin.PLUGIN_ID, - "Couldn't set " + optionId + " option", e)); - } } public void setOption(final String optionId, final String[] values) throws CoreException { @@ -80,12 +74,9 @@ public void setOption(final String optionId, final String[] values) throws CoreE final IOption option = tool.getOptionBySuperClassId(optionId); config.setOption(tool, option, values); } + } catch (BuildException e) { + throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Couldn't set " + optionId + " option", e)); } - catch (BuildException e) { - throw new CoreException(new Status(IStatus.ERROR, - MavenNarPlugin.PLUGIN_ID, - "Couldn't set " + optionId + " option", e)); - } } public void setOption(final String optionId, final boolean value) throws CoreException { @@ -94,11 +85,8 @@ public void setOption(final String optionId, final boolean value) throws CoreExc final IOption option = tool.getOptionBySuperClassId(optionId); config.setOption(tool, option, value); } + } catch (BuildException e) { + throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Couldn't set " + optionId + " option", e)); } - catch (BuildException e) { - throw new CoreException(new Status(IStatus.ERROR, - MavenNarPlugin.PLUGIN_ID, - "Couldn't set " + optionId + " option", e)); - } } } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/SettingsSynchroniser.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/SettingsSynchroniser.java index 3a99d1f..b05879b 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/SettingsSynchroniser.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/SettingsSynchroniser.java @@ -26,10 +26,8 @@ public interface SettingsSynchroniser { - public void fullSync(ICConfigurationDescription cfg, - NarBuildArtifact artifactSettings) throws CoreException; + public void fullSync(ICConfigurationDescription cfg, NarBuildArtifact artifactSettings) throws CoreException; - public void pathsOnlySync(ICConfigurationDescription cfg, - NarBuildArtifact artifactSettings) throws CoreException; + public void pathsOnlySync(ICConfigurationDescription cfg, NarBuildArtifact artifactSettings) throws CoreException; } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/SynchroniserFactory.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/SynchroniserFactory.java index 54a32bf..e6208c1 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/SynchroniserFactory.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/cdt/SynchroniserFactory.java @@ -27,8 +27,7 @@ public final class SynchroniserFactory { - public static AbstractSettingsSynchroniser getSettingsSynchroniser( - final String os, final String linkerName) throws CoreException { + public static AbstractSettingsSynchroniser getSettingsSynchroniser(final String os, final String linkerName) throws CoreException { if ("Windows".equals(os)) { if ("msvc".equals(linkerName)) { // TODO "Microsoft Visual C++"; @@ -90,9 +89,6 @@ public static AbstractSettingsSynchroniser getSettingsSynchroniser( // TODO "AIX GCC"; } } - throw new CoreException(new Status(IStatus.ERROR, - MavenNarPlugin.PLUGIN_ID, - "Unknown os-linker combination \"" + os + "-" + linkerName - + "\"")); + throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Unknown os-linker combination \"" + os + "-" + linkerName + "\"")); } } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/model/NarBuildArtifact.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/model/NarBuildArtifact.java index bf92942..99eee74 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/model/NarBuildArtifact.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/model/NarBuildArtifact.java @@ -24,7 +24,7 @@ import java.util.List; public class NarBuildArtifact { - + public static final String STATIC = "static"; public static final String SHARED = "shared"; public static final String EXECUTABLE = "executable"; @@ -34,21 +34,21 @@ public class NarBuildArtifact { private String configName; private String artifactName; - private String type; + private String type; private NarCompiler cppSettings; private NarCompiler cSettings; private NarLinker linkerSettings; - + private List projectReferences = new ArrayList(); - + private List javahIncludePaths = new ArrayList(); private List javaIncludePaths = new ArrayList(); private List dependencyIncludePaths = new ArrayList(); - + private List dependencyLibs = new ArrayList(); private List dependencySysLibs = new ArrayList(); private List dependencyOptions = new ArrayList(); - + public String getConfigName() { return configName; } @@ -57,75 +57,103 @@ public String getArtifactName() { return artifactName; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.m2e.cdt.internal.INarArtifactSettings#getType() */ public String getType() { return type; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.m2e.cdt.internal.INarArtifactSettings#getCppSettings() */ public NarCompiler getCppSettings() { return cppSettings; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.m2e.cdt.internal.INarArtifactSettings#getcSettings() */ public NarCompiler getCSettings() { return cSettings; } - /* (non-Javadoc) - * @see org.eclipse.m2e.cdt.internal.INarArtifactSettings#getLinkerSettings() + /* + * (non-Javadoc) + * + * @see + * org.eclipse.m2e.cdt.internal.INarArtifactSettings#getLinkerSettings() */ public NarLinker getLinkerSettings() { return linkerSettings; } - + public List getProjectReferences() { return projectReferences; } - /* (non-Javadoc) - * @see org.eclipse.m2e.cdt.internal.INarArtifactSettings#getDependencyIncludePaths() + /* + * (non-Javadoc) + * + * @see + * org.eclipse.m2e.cdt.internal.INarArtifactSettings#getDependencyIncludePaths + * () */ public List getDependencyIncludePaths() { return dependencyIncludePaths; } - /* (non-Javadoc) - * @see org.eclipse.m2e.cdt.internal.INarArtifactSettings#getJavahIncludePaths() + /* + * (non-Javadoc) + * + * @see + * org.eclipse.m2e.cdt.internal.INarArtifactSettings#getJavahIncludePaths() */ public List getJavahIncludePaths() { return javahIncludePaths; } - /* (non-Javadoc) - * @see org.eclipse.m2e.cdt.internal.INarArtifactSettings#getJavaIncludePaths() + /* + * (non-Javadoc) + * + * @see + * org.eclipse.m2e.cdt.internal.INarArtifactSettings#getJavaIncludePaths() */ public List getJavaIncludePaths() { return javaIncludePaths; } - /* (non-Javadoc) - * @see org.eclipse.m2e.cdt.internal.INarArtifactSettings#getDependencyLibs() + /* + * (non-Javadoc) + * + * @see + * org.eclipse.m2e.cdt.internal.INarArtifactSettings#getDependencyLibs() */ public List getDependencyLibs() { return dependencyLibs; } - - /* (non-Javadoc) - * @see org.eclipse.m2e.cdt.internal.INarArtifactSettings#getDependencySysLibs() + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.m2e.cdt.internal.INarArtifactSettings#getDependencySysLibs() */ public List getDependencySysLibs() { return dependencySysLibs; } - - /* (non-Javadoc) - * @see org.eclipse.m2e.cdt.internal.INarArtifactSettings#getDependencyOptions() + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.m2e.cdt.internal.INarArtifactSettings#getDependencyOptions() */ public List getDependencyOptions() { return dependencyOptions; @@ -154,7 +182,7 @@ public void setCSettings(NarCompiler cSettings) { public void setLinkerSettings(NarLinker linkerSettings) { this.linkerSettings = linkerSettings; } - + public static boolean isSharedLibrary(final String type) { return SHARED.equals(type) || JNI.equals(type) || PLUGIN.equals(type); } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/model/NarCompiler.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/model/NarCompiler.java index 903158e..c34293d 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/model/NarCompiler.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/model/NarCompiler.java @@ -30,13 +30,13 @@ public class NarCompiler { public enum OptimizationLevel { NONE, SIZE, MINIMAL, SPEED, FULL, AGGRESSIVE, EXTREME, UNSAFE } - + private String name; private final List includePaths = new ArrayList(); private final List systemIncludePaths = new ArrayList(); private final List sourceDirectories = new ArrayList(); - + private boolean debug; private boolean rtti; private OptimizationLevel optimize; @@ -56,77 +56,101 @@ public void setName(String name) { this.name = name; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.m2e.cdt.internal.INarCompilerSettings#getIncludePaths() */ public List getIncludePaths() { return includePaths; } - /* (non-Javadoc) - * @see org.eclipse.m2e.cdt.internal.INarCompilerSettings#getSystemIncludePaths() + /* + * (non-Javadoc) + * + * @see + * org.eclipse.m2e.cdt.internal.INarCompilerSettings#getSystemIncludePaths() */ public List getSystemIncludePaths() { return systemIncludePaths; } - /* (non-Javadoc) - * @see org.eclipse.m2e.cdt.internal.INarCompilerSettings#getSourceDirectories() + /* + * (non-Javadoc) + * + * @see + * org.eclipse.m2e.cdt.internal.INarCompilerSettings#getSourceDirectories() */ public List getSourceDirectories() { return sourceDirectories; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.m2e.cdt.internal.INarCompilerSettings#isDebug() */ public boolean isDebug() { return debug; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.m2e.cdt.internal.INarCompilerSettings#isRtti() */ public boolean isRtti() { return rtti; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.m2e.cdt.internal.INarCompilerSettings#getOptimize() */ public OptimizationLevel getOptimize() { return optimize; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.m2e.cdt.internal.INarCompilerSettings#isMultiThreaded() */ public boolean isMultiThreaded() { return multiThreaded; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.m2e.cdt.internal.INarCompilerSettings#isExceptions() */ public boolean isExceptions() { return exceptions; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.m2e.cdt.internal.INarCompilerSettings#getDefines() */ public List getDefines() { return defines; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.m2e.cdt.internal.INarCompilerSettings#getUndefines() */ public List getUndefines() { return undefines; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.m2e.cdt.internal.INarCompilerSettings#getOptions() */ public List getOptions() { @@ -160,6 +184,5 @@ public Set getIncludes() { public Set getExcludes() { return excludes; } - - + } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/model/NarExecution.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/model/NarExecution.java index bd28dca..83f77e0 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/model/NarExecution.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/model/NarExecution.java @@ -30,32 +30,34 @@ public class NarExecution { public static final String TEST = "test"; private final MojoExecution mojoExecution; - private boolean skip; - private String os; - private String linkerName; + private boolean skip; + private String os; + private String linkerName; private List artifactSettings = new ArrayList(); public NarExecution(final MojoExecution mojoExecution) { this.mojoExecution = mojoExecution; } - + public MojoExecution getMojoExecution() { return mojoExecution; } - + public boolean isSkip() { return skip; } - + public String getOS() { return os; } - + public String getLinkerName() { return linkerName; } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.eclipse.m2e.cdt.internal.INarSettings#getArtifactSettings() */ public List getArtifactSettings() { diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/model/NarLib.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/model/NarLib.java index eb35e60..eb03d8a 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/model/NarLib.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/model/NarLib.java @@ -24,12 +24,14 @@ public class NarLib { private String name; - + private String type; private File directory; - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.m2e.cdt.internal.INarLibSettings#getName() */ public String getName() { @@ -40,7 +42,9 @@ public void setName(String name) { this.name = name; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.m2e.cdt.internal.INarLibSettings#getType() */ public String getType() { @@ -51,7 +55,9 @@ public void setType(String type) { this.type = type; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.m2e.cdt.internal.INarLibSettings#getDirectory() */ public File getDirectory() { diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/model/NarLinker.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/model/NarLinker.java index a9751c0..c68ad44 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/model/NarLinker.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/model/NarLinker.java @@ -27,7 +27,7 @@ public class NarLinker { private String name; private List libs = new ArrayList(); private List sysLibs = new ArrayList(); - + private boolean incremental; private boolean map; private final List options = new ArrayList(); @@ -41,35 +41,45 @@ public void setName(String name) { this.name = name; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.m2e.cdt.internal.INarLinkerSettings#getLibs() */ public List getLibs() { return libs; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.m2e.cdt.internal.INarLinkerSettings#getSysLibs() */ public List getSysLibs() { return sysLibs; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.m2e.cdt.internal.INarLinkerSettings#isIncremental() */ public boolean isIncremental() { return incremental; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.m2e.cdt.internal.INarLinkerSettings#isMap() */ public boolean isMap() { return map; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.m2e.cdt.internal.INarLinkerSettings#getOptions() */ public List getOptions() { @@ -91,5 +101,5 @@ public boolean isLinkCpp() { public void setLinkCpp(boolean linkCpp) { this.linkCpp = linkCpp; } - + } diff --git a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/model/NarSysLib.java b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/model/NarSysLib.java index fd5f555..58ca91e 100644 --- a/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/model/NarSysLib.java +++ b/com.github.sdedwards.m2e-nar/src/com/github/sdedwards/m2e_nar/internal/model/NarSysLib.java @@ -19,14 +19,15 @@ */ package com.github.sdedwards.m2e_nar.internal.model; - public class NarSysLib { private String name; - + private String type; - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.m2e.cdt.internal.INarSysLibSettings#getName() */ public String getName() { @@ -37,7 +38,9 @@ public void setName(String name) { this.name = name; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.m2e.cdt.internal.INarSysLibSettings#getType() */ public String getType() { diff --git a/eclipse_formatter.xml b/eclipse_formatter.xml new file mode 100644 index 0000000..2c6c6d9 --- /dev/null +++ b/eclipse_formatter.xml @@ -0,0 +1,291 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +