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 838ac63..5bc212d 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 @@ com.github.maven-nar nar-maven-plugin - 3.2.3 + 3.5.1 diff --git a/com.github.sdedwards.m2e-nar/.classpath b/com.github.sdedwards.m2e-nar/.classpath index 0b1bcf9..49ca39d 100644 --- a/com.github.sdedwards.m2e-nar/.classpath +++ b/com.github.sdedwards.m2e-nar/.classpath @@ -1,5 +1,7 @@ + + diff --git a/com.github.sdedwards.m2e-nar/META-INF/MANIFEST.MF b/com.github.sdedwards.m2e-nar/META-INF/MANIFEST.MF index 8798089..39fe43c 100644 --- a/com.github.sdedwards.m2e-nar/META-INF/MANIFEST.MF +++ b/com.github.sdedwards.m2e-nar/META-INF/MANIFEST.MF @@ -21,3 +21,6 @@ Export-Package: com.github.maven_nar;x-internal:=true, com.github.sdedwards.m2e_nar, com.github.sdedwards.m2e_nar.internal;x-internal:=true, com.github.sdedwards.m2e_nar.internal.model;x-internal:=true +Bundle-ClassPath: lib/maven-common-artifact-filters-1.4.jar, + lib/maven-plugin-annotations-3.2.jar, + . diff --git a/com.github.sdedwards.m2e-nar/NOTICE b/com.github.sdedwards.m2e-nar/NOTICE index 89497d9..16b932e 100644 --- a/com.github.sdedwards.m2e-nar/NOTICE +++ b/com.github.sdedwards.m2e-nar/NOTICE @@ -1,7 +1,15 @@ NAR Maven Plugin Integration for Eclipse -Copyright 2015 Stephen Edwards +Copyright 2015-2018 Stephen Edwards Portions of this code -- specifically, most of the com.github.maven_nar package -- were adapted from the nar-maven-plugin open source project (http://maven-nar.github.io/) +Maven Plugin Java 5 Annotations +Copyright 2004-2012 The Apache Software Foundation + +Maven Common Artifact Filters +Copyright 2002-2011 The Apache Software Foundation + +This product includes software developed at +The Apache Software Foundation (http://www.apache.org/). diff --git a/com.github.sdedwards.m2e-nar/build.properties b/com.github.sdedwards.m2e-nar/build.properties index 9dcbdf6..fb62b02 100644 --- a/com.github.sdedwards.m2e-nar/build.properties +++ b/com.github.sdedwards.m2e-nar/build.properties @@ -2,5 +2,7 @@ output.. = target/classes/ bin.includes = META-INF/,\ plugin.xml,\ lifecycle-mapping-metadata.xml,\ - . + .,\ + lib/maven-common-artifact-filters-1.4.jar,\ + lib/maven-plugin-annotations-3.2.jar source.. = src/ diff --git a/com.github.sdedwards.m2e-nar/lib/maven-common-artifact-filters-1.4.jar b/com.github.sdedwards.m2e-nar/lib/maven-common-artifact-filters-1.4.jar new file mode 100644 index 0000000..035128f Binary files /dev/null and b/com.github.sdedwards.m2e-nar/lib/maven-common-artifact-filters-1.4.jar differ diff --git a/com.github.sdedwards.m2e-nar/lib/maven-plugin-annotations-3.2.jar b/com.github.sdedwards.m2e-nar/lib/maven-plugin-annotations-3.2.jar new file mode 100644 index 0000000..acf6247 Binary files /dev/null and b/com.github.sdedwards.m2e-nar/lib/maven-plugin-annotations-3.2.jar differ 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 c746609..c8a33e5 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 @@ -29,9 +29,9 @@ import java.util.LinkedList; import java.util.List; -import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Parameter; import com.github.sdedwards.m2e_nar.internal.cdt.CdtUtils; @@ -40,111 +40,114 @@ */ 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; + /** + * C++ Compiler + */ + @Parameter + private Cpp cpp; + + /** + * C Compiler + */ + @Parameter + private C c; + + /** + * Fortran Compiler + */ + @Parameter + private Fortran fortran; + + /** + * Resource Compiler + */ + @Parameter + private Resource resource; + + /** + * IDL Compiler + */ + @Parameter + private IDL idl; + + /** + * Message Compiler + */ + @Parameter + 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(defaultValue = "false") + protected boolean onlySpecifiedCompilers; + + /** + * Do we log commands that is executed to produce the end-result? + * Conception was to allow eclipse to sniff out include-paths from compile. + */ + @Parameter + protected int commandLogLevel = 3; + + /** + * Maximum number of Cores/CPU's to use. 0 means unlimited. + */ + @Parameter + private int maxCores = 0; + + /** + * Fail on compilation/linking error. + */ + @Parameter(defaultValue = "true", required = true) + private boolean failOnError; + + /** + * Sets the type of runtime library, possible values "dynamic", "static". + */ + @Parameter(defaultValue = "dynamic", required = true) + private String runtime; + + /** + * Set use of libtool. If set to true, the "libtool " will be prepended to the + * command line for compatible + * processors. + */ + @Parameter(defaultValue = "false", required = true) + private boolean libtool; + + /** + * List of tests to create + */ + @Parameter + private List tests; + + /** + * Java info for includes and linking + */ + @Parameter + private Java java; + + /** + * To support scanning the code with HPE Fortify. + *

+ * The attribute functions as a flag that indicates Fortify is required, + * and the value is an ID, prepended to the command line as + * {@code sourceanalyzer –b }. + *

+ */ + @Parameter(defaultValue = "") + private String fortifyID; + + + /** + * Flag to cpptasks to indicate whether linker options should be decorated or + * not + */ + @Parameter + protected boolean decorateLinkerOptions; private NarInfo narInfo; @@ -412,7 +415,8 @@ protected File getLibraryPath(NarArtifact dependency) throws MojoFailureExceptio List libraries = new ArrayList(); if (test != null) { // Add the library of this package if it exists - final String linkType = test.getLink(); + List myLibs = new ArrayList(getLibraries()); + final String linkType = test.getLink(myLibs); getLog().debug("Test: " + test.getName() + ", link: " + linkType); boolean found = false; for (Library lib : getLibraries()) { @@ -423,7 +427,7 @@ protected File getLibraryPath(NarArtifact dependency) throws MojoFailureExceptio } 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 File dir = new File(getMavenProject().getBasedir(), CdtUtils.DEFAULT_CONFIG_NAME_PREFIX + test.getLink(myLibs)); final Lib library = new Lib(); library.setName(getOutput(linkType)); library.setDirectory(dir); 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 2675cb4..76081b9 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 @@ -25,6 +25,7 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -38,6 +39,14 @@ import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException; +import org.apache.maven.shared.artifact.filter.collection.ArtifactIdFilter; +import org.apache.maven.shared.artifact.filter.collection.FilterArtifacts; +import org.apache.maven.shared.artifact.filter.collection.GroupIdFilter; +import org.apache.maven.shared.artifact.filter.collection.ScopeFilter; +import org.codehaus.plexus.util.StringUtils; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.m2e.core.project.IMavenProjectFacade; @@ -52,38 +61,52 @@ */ public abstract class AbstractDependencyMojo extends AbstractNarMojo { - /** - * @parameter default-value="${localRepository}" - * @required - * @readonly - */ - private ArtifactRepository localRepository; - - /** - * Artifact resolver, needed to download the attached nar files. - * - * @component role="org.apache.maven.artifact.resolver.ArtifactResolver" - * @required - * @readonly - */ - protected ArtifactResolver artifactResolver; - - /** - * Remote repositories which will be searched for nar attachments. - * - * @parameter default-value="${project.remoteArtifactRepositories}" - * @required - * @readonly - */ - protected List remoteArtifactRepositories; - - /** - * The plugin remote repositories declared in the pom. - * - * @parameter default-value="${project.pluginArtifactRepositories}" - * @since 2.2 - */ - // private List remotePluginRepositories; + @Parameter(defaultValue = "${localRepository}", required = true, readonly = true) + private ArtifactRepository localRepository; + + /** + * Artifact resolver, needed to download the attached nar files. + */ + @Component(role = org.apache.maven.artifact.resolver.ArtifactResolver.class) + protected ArtifactResolver artifactResolver; + + /** + * Remote repositories which will be searched for nar attachments. + */ + @Parameter(defaultValue = "${project.remoteArtifactRepositories}", required = true, readonly = true) + protected List remoteArtifactRepositories; + + /** + * Comma separated list of Artifact names to exclude. + * + * @since 2.0 + */ + @Parameter(property = "excludeArtifactIds", defaultValue = "") + protected String excludeArtifactIds; + + /** + * Comma separated list of Artifact names to include. + * + * @since 2.0 + */ + @Parameter(property = "includeArtifactIds", defaultValue = "") + protected String includeArtifactIds; + + /** + * Comma separated list of GroupId Names to exclude. + * + * @since 2.0 + */ + @Parameter(property = "excludeGroupIds", defaultValue = "") + protected String excludeGroupIds; + + /** + * Comma separated list of GroupIds to include. + * + * @since 2.0 + */ + @Parameter(property = "includeGroupIds", defaultValue = "") + protected String includeGroupIds; protected List narDependencies = null; @@ -95,8 +118,6 @@ protected final List getRemoteRepositories() { return remoteArtifactRepositories; } - protected abstract List getArtifacts(); - /** * Returns dependencies which are dependent on NAR files (i.e. contain * NarInfo) @@ -166,48 +187,84 @@ private final NarInfo getNarInfo(Artifact dependency, EclipseNarLayout layout) t return narInfo; } - 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(); - - // Skip dependencies that are already available - // eg sibling sub-module dependencies in compile only builds - if (dependency.getNarInfo() == null) { - continue; - } - - String binding = getBinding(/* library, */dependency); + public final List getAllAttachedNarArtifacts(final List narArtifacts, + List libraries) throws MojoExecutionException, MojoFailureException { + final List artifactList = new ArrayList(); + for (NarArtifact dependency : narArtifacts) { + // Skip dependencies that are already available + // eg sibling sub-module dependencies in compile only builds + if (dependency.getNarInfo() == null) { + continue; + } + if ("NAR".equalsIgnoreCase(getMavenProject().getPackaging())) { + final String bindings[] = getBindings(libraries, dependency); + + // TODO: dependency.getFile(); find out what the stored pom says + // about this - what nars should exist, what layout are they + // using... + for (final String binding : bindings) { + artifactList.addAll(getAttachedNarArtifacts(dependency, /* library. */ + getAOL(), binding)); + } + } else { + artifactList.addAll(getAttachedNarArtifacts(dependency, getAOL(), Library.EXECUTABLE)); + artifactList.addAll(getAttachedNarArtifacts(dependency, getAOL(), Library.SHARED)); + artifactList.addAll(getAttachedNarArtifacts(dependency, getAOL(), Library.JNI)); + artifactList.addAll(getAttachedNarArtifacts(dependency, getAOL(), Library.STATIC)); + } + artifactList.addAll(getAttachedNarArtifacts(dependency, null, NarConstants.NAR_NO_ARCH)); + } + return artifactList; + } + + protected String[] getBindings(List libraries, NarArtifact dependency) + throws MojoFailureException, MojoExecutionException { + + Set bindings = new HashSet(); + if (libraries != null){ + for (Object library : libraries) { + Executable exec = (Executable) library; + // how does this project specify the dependency is used + String binding = exec.getBinding(dependency); + if( null != binding ) + bindings.add(binding); + } + } + + // - if it is specified but the atrifact is not available should fail. + // otherwise + // how does the artifact specify it should be used by default + // - + // whats the preference for this type of library to use (shared - shared, + // static - static...) + + // library.getType() + if (bindings.isEmpty()) + bindings.add(dependency.getNarInfo().getBinding(getAOL(), Library.STATIC)); + + return bindings.toArray(new String[1]); + } + + protected String getBinding(Executable exec, NarArtifact dependency) + throws MojoFailureException, MojoExecutionException { + + // how does this project specify the dependency is used + String binding = exec.getBinding(dependency); + + // - if it is specified but the atrifact is not available should fail. + // otherwise + // how does the artifact specify it should be used by default + // - + // whats the preference for this type of library to use (shared - shared, + // static - static...) + + // library.getType() + if (binding == null) + binding = dependency.getNarInfo().getBinding(getAOL(), Library.STATIC); + + return binding; + } - // 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)); - } - return artifactList; - } - - 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 - // - // - what is the preference for this type of library to use (shared - - // shared, static - static...) - - // library.getType() - String binding = dependency.getNarInfo().getBinding( - /* library. */getAOL(), /* type != null ? type : */ - ILibrary.STATIC); - return binding; - } public File getArtifactDirectory(NarArtifact dependency, File unpackDirectory) { File targetDirectory = dependency.getNarInfo().getTargetDirectory(); @@ -218,74 +275,120 @@ public File getArtifactDirectory(NarArtifact dependency, File unpackDirectory) { } } - 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); - // FIXME Move this to NarInfo.... - if (nars != null) { - for (int j = 0; j < nars.length; j++) { - getLog().debug(" Checking: " + nars[j]); - if (nars[j].equals("")) { - continue; - } - String[] nar = nars[j].split(":", 5); - if (nar.length >= 4) { - try { - String groupId = nar[0].trim(); - String artifactId = nar[1].trim(); - String ext = nar[2].trim(); - String classifier = nar[3].trim(); - // translate for instance g++ to gcc... - AOL aolString = narInfo.getAOL(aol); - if (aolString != null) { - 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(), - dependency.getFile())); - } catch (InvalidVersionSpecificationException 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] - // + "' for type: " + type - ); - } - } - } - return artifactList; - } - - @SuppressWarnings("deprecation") - 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())); - } - getLog().debug("}"); - - for (Iterator i = dependencies.iterator(); i.hasNext();) { - Artifact dependency = (Artifact) i.next(); - try { - getLog().debug("Resolving " + dependency); - artifactResolver.resolve(dependency, remoteArtifactRepositories, getLocalRepository()); - } catch (ArtifactNotFoundException e) { - String message = "nar not found " + dependency.getId(); - throw new MojoExecutionException(message, e); - } catch (ArtifactResolutionException e) { - String message = "nar cannot resolve " + dependency.getId(); - throw new MojoExecutionException(message, e); - } - } - } - + /** + * Returns the artifacts which must be taken in account for the Mojo. + * + * @return Artifacts + */ + protected abstract ScopeFilter getArtifactScopeFilter(); + + /** + * Returns the attached NAR Artifacts (AOL and noarch artifacts) from the NAR + * dependencies artifacts of the project. + * The artifacts which will be processed are those returned by the method + * getArtifacts() which must be implemented + * in each class which extends AbstractDependencyMojo. + * + * @return Attached NAR Artifacts + * @throws MojoFailureException + * @throws MojoExecutionException + * + * @see getArtifacts + */ + protected List getAttachedNarArtifacts(List libraries) + throws MojoFailureException, MojoExecutionException { + getLog().info("Getting Nar dependencies"); + final List narArtifacts = getNarArtifacts(); + final List attachedNarArtifacts = getAllAttachedNarArtifacts(narArtifacts, libraries); + return attachedNarArtifacts; + } + + private List getAttachedNarArtifacts(final NarArtifact dependency, final AOL aol, + final String type) throws MojoExecutionException, MojoFailureException { + getLog().debug("GetNarDependencies for " + dependency + ", aol: " + aol + ", type: " + type); + final List artifactList = new ArrayList(); + final NarInfo narInfo = dependency.getNarInfo(); + final String[] nars = narInfo.getAttachedNars(aol, type); + // FIXME Move this to NarInfo.... + if (nars != null) { + for (final String nar2 : nars) { + getLog().debug(" Checking: " + nar2); + if (nar2.equals("")) { + continue; + } + final String[] nar = nar2.split(":", 5); + if (nar.length >= 4) { + try { + final String groupId = nar[0].trim(); + final String artifactId = nar[1].trim(); + final String ext = nar[2].trim(); + String classifier = nar[3].trim(); + // translate for instance g++ to gcc... + final AOL aolString = narInfo.getAOL(aol); + if (aolString != null) { + classifier = NarUtil.replace("${aol}", aolString.toString(), classifier); + } + final 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 (final InvalidVersionSpecificationException e) { + throw new MojoExecutionException("Error while reading nar file for dependency " + dependency, e); + } + } else { + getLog().warn("nars property in " + dependency.getArtifactId() + " contains invalid field: '" + nar2); + } + } + } + return artifactList; + } + + @SuppressWarnings("deprecation") + public final void downloadAttachedNars(final List dependencies) + throws MojoExecutionException, MojoFailureException { + getLog().debug("Download for NarDependencies {"); + for (final AttachedNarArtifact attachedNarArtifact : dependencies) { + getLog().debug(" - " + attachedNarArtifact); + } + getLog().debug("}"); + + for (final AttachedNarArtifact attachedNarArtifact : dependencies) { + try { + getLog().debug("Resolving " + attachedNarArtifact); + this.artifactResolver.resolve(attachedNarArtifact, this.remoteArtifactRepositories, getLocalRepository()); + } catch (final ArtifactNotFoundException e) { + final String message = "nar not found " + attachedNarArtifact.getId(); + throw new MojoExecutionException(message, e); + } catch (final ArtifactResolutionException e) { + final String message = "nar cannot resolve " + attachedNarArtifact.getId(); + throw new MojoExecutionException(message, e); + } + } + } + + @SuppressWarnings("unchecked") 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(); + FilterArtifacts filter = new FilterArtifacts(); + + filter.addFilter(new GroupIdFilter(cleanToBeTokenizedString(this.includeGroupIds), + cleanToBeTokenizedString(this.excludeGroupIds))); + + filter.addFilter(new ArtifactIdFilter(cleanToBeTokenizedString(this.includeArtifactIds), + cleanToBeTokenizedString(this.excludeArtifactIds))); + + filter.addFilter(getArtifactScopeFilter()); + + Set artifacts = getMavenProject().getArtifacts(); + + // perform filtering + try { + artifacts = filter.filter(artifacts); + } catch (ArtifactFilterException e) { + throw new MojoExecutionException(e.getMessage(), e); + } + + for (final Artifact dependency : artifacts) { getLog().debug("Examining artifact for NarInfo: " + dependency); NarLayout layout; @@ -342,4 +445,17 @@ private EclipseNarLayout resolveEclipseProject(final Artifact artifact, final Co } return null; } + + // + // clean up configuration string before it can be tokenized + // + private static String cleanToBeTokenizedString(String str) { + String ret = ""; + if (!StringUtils.isEmpty(str)) { + // remove initial and ending spaces, plus all spaces next to commas + ret = str.trim().replaceAll("[\\s]*,[\\s]*", ","); + } + + return ret; + } } 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 5235178..37589fa 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 @@ -32,6 +32,7 @@ import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; /** @@ -42,49 +43,45 @@ public abstract class AbstractNarMojo implements NarConstants { - /** - * Skip running of NAR plugins (any) altogether. - * - * @parameter property="nar.skip" default-value="false" - */ - private boolean skip; - - /** - * Skip the tests. Listens to Maven's general 'maven.skip.test'. - * - * @parameter property="maven.test.skip" - */ - boolean skipTests; - - /** - * Ignore errors and failures. - * - * @parameter property="nar.ignore" default-value="false" - */ - private boolean ignore; - - /** - * The Architecture for the nar, Some choices are: "x86", "i386", "amd64", "ppc", "sparc", ... Defaults to a derived - * value from ${os.arch} - * - * @parameter property="nar.arch" - */ - private String architecture; - - /** - * The Operating System for the nar. Some choices are: "Windows", "Linux", "MacOSX", "SunOS", ... Defaults to a - * derived value from ${os.name} FIXME table missing - * - * @parameter property="nar.os" - */ - private String os; - - /** - * Architecture-OS-Linker name. Defaults to: arch-os-linker. - * - * @parameter default-value="" - */ - private String aol; + /** + * Skip running of NAR plugins (any) altogether. + */ + @Parameter(property = "nar.skip", defaultValue = "false") + protected boolean skip; + + /** + * Skip the tests. Listens to Maven's general 'maven.skip.test'. + */ + @Parameter(property = "maven.test.skip") + boolean skipTests; + + /** + * Ignore errors and failures. + */ + @Parameter(property = "nar.ignore", defaultValue = "false") + private boolean ignore; + + /** + * The Architecture for the nar, Some choices are: "x86", "i386", "amd64", + * "ppc", "sparc", ... Defaults to a derived + * value from ${os.arch} + */ + @Parameter(property = "nar.arch") + private String architecture; + + /** + * The Operating System for the nar. Some choices are: "Windows", "Linux", + * "MacOSX", "SunOS","AIX" ... Defaults to a + * derived value from ${os.name} FIXME table missing + */ + @Parameter(property = "nar.os") + private String os; + + /** + * Architecture-OS-Linker name. Defaults to: arch-os-linker. + */ + @Parameter(defaultValue = "") + private String aol; /** * Additional classifier suffix. Defaults to: "" @@ -93,99 +90,93 @@ public abstract class AbstractNarMojo */ private String aolSuffix; - /** - * Linker - * - * @parameter default-value="" - */ - private Linker linker; - - /** - * @parameter property="project.build.directory" - * @readonly - */ - private File outputDirectory; - - /** - * @parameter property="project.build.outputDirectory" - * @readonly - */ - protected File classesDirectory; - - /** - * Name of the output - * - for jni default-value="${project.artifactId}-${project.version}" - * - for libs default-value="${project.artifactId}-${project.version}" - * - for exe default-value="${project.artifactId}" - * -- for tests default-value="${test.name}" - * - * @parameter - */ - private String output; - - /** - * @parameter property="project.basedir" - * @readonly - */ - private File baseDir; - - /** - * @parameter property="project.build.finalName" - * @readonly - */ - private String finalName; - - /** - * Target directory for Nar file construction. Defaults to "${project.build.directory}/nar" for "nar-compile" goal - * - * @parameter default-value="" - */ - private File targetDirectory; - - /** - * Target directory for Nar test construction. Defaults to "${project.build.directory}/test-nar" for "nar-testCompile" goal - * - * @parameter default-value="" - */ - private File testTargetDirectory; - - /** - * Target directory for Nar file unpacking. Defaults to "${targetDirectory}" - * - * @parameter default-value="" - */ - private File unpackDirectory; - - /** - * Target directory for Nar test unpacking. Defaults to "${testTargetDirectory}" - * - * @parameter default-value="" - */ - private File testUnpackDirectory; - - /** - * List of classifiers which you want download/unpack/assemble - * Example ppc-MacOSX-g++, x86-Windows-msvc, i386-Linux-g++. - * Not setting means all. - * - * @parameter default-value="" - */ - protected List classifiers; + /** + * Linker + */ + @Parameter + private Linker linker; + + // these could be obtained from an injected project model. + + @Parameter(property = "project.build.directory", readonly = true) + private File outputDirectory; + + @Parameter(property = "project.build.outputDirectory", readonly = true) + protected File classesDirectory; + + /** + * Name of the output + * - for jni default-value="${project.artifactId}-${project.version}" + * - for libs default-value="${project.artifactId}-${project.version}" + * - for exe default-value="${project.artifactId}" + * -- for tests default-value="${test.name}" + * + */ + @Parameter + private String output; + + @Parameter(property = "project.basedir", readonly = true) + private File baseDir; + + /** + * Target directory for Nar file construction. Defaults to + * "${project.build.directory}/nar" for "nar-compile" goal + */ + @Parameter + private File targetDirectory; + + /** + * Target directory for Nar test construction. Defaults to + * "${project.build.directory}/test-nar" for "nar-testCompile" goal + */ + @Parameter + private File testTargetDirectory; + + /** + * Target directory for Nar file unpacking. Defaults to "${targetDirectory}" + */ + @Parameter + private File unpackDirectory; + + /** + * Target directory for Nar test unpacking. Defaults to + * "${testTargetDirectory}" + */ + @Parameter + private File testUnpackDirectory; /** - * List of libraries to create + * NARVersionInfo for Windows binaries * - * @parameter default-value="" - */ - protected List libraries; - - /** - * Layout to be used for building and unpacking artifacts - * - * @parameter property="nar.layout" default-value="com.github.maven_nar.NarLayout21" - * @required */ - private String layout; + //@Parameter + //private NARVersionInfo versionInfo; + + /** + * List of classifiers which you want download/unpack/assemble + * Example ppc-MacOSX-g++, x86-Windows-msvc, i386-Linux-g++. + * Not setting means all. + */ + @Parameter + protected List classifiers; + + /** + * List of libraries to create + */ + @Parameter + protected List libraries; + + /** + * Name of the libraries included + */ + @Parameter + private String libsName; + + /** + * Layout to be used for building and unpacking artifacts + */ + @Parameter(property = "nar.layout", defaultValue = "com.github.maven_nar.NarLayout21", required = true) + private String layout; private NarLayout narLayout; @@ -314,11 +305,6 @@ protected final File getOutputDirectory() return outputDirectory; } - protected final String getFinalName() - { - return finalName; - } - protected final File getTargetDirectory() { return targetDirectory; 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 96e1dac..cca0c73 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 @@ -33,6 +33,7 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.StringUtils; @@ -43,223 +44,198 @@ */ 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; - - /** - * Additional options for the compiler when running in the nar-testCompile phase. - * - * @parameter default-value="" - */ - private List testOptions; - - /** - * 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; + /** + * 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 + private String name; + + /** + * The prefix for the compiler. + */ + @Parameter + private String prefix; + + /** + * Path location of the compile tool + */ + @Parameter + private String toolPath; + + /** + * Source directory for native files + */ + @Parameter(defaultValue = "${basedir}/src/main", required = true) + private File sourceDirectory; + + /** + * Source directory for native test files + */ + @Parameter(defaultValue = "${basedir}/src/test", required = true) + private File testSourceDirectory; + + /** + * To use full path for the filenames. + * false to have "relative" path + * true to have "absolute" path + * absolute: will give path from filesystem root "/" + * relative: will give relative path from "workdir" which is usually after "${basedir}/src/main" + */ + @Parameter(required = true) + private boolean gccFileAbsolutePath = false; + + /** + * Include patterns for sources + */ + @Parameter(required = true) + private Set includes = new HashSet(); + + /** + * Exclude patterns for sources + */ + @Parameter(required = true) + private Set excludes = new HashSet(); + + /** + * Include patterns for test sources + */ + @Parameter(required = true) + private Set testIncludes = new HashSet(); + + /** + * Exclude patterns for test sources + */ + @Parameter(required = true) + private Set testExcludes = new HashSet(); + + @Parameter(defaultValue = "false", required = false) + private boolean ccache = false; + + /** + * Compile with debug information. + */ + @Parameter(required = true) + private boolean debug = false; + + /** + * Enables generation of exception handling code. + */ + @Parameter(defaultValue = "true", required = true) + private boolean exceptions = true; + + /** + * Enables run-time type information. + */ + @Parameter(defaultValue = "true", required = true) + private boolean rtti = true; + + /** + * Sets optimization. Possible choices are: "none", "size", "minimal", + * "speed", "full", "aggressive", "extreme", + * "unsafe". + */ + @Parameter(defaultValue = "none", required = true) + private String optimize = "none"; + + /** + * Enables or disables generation of multi-threaded code. Default value: + * false, except on Windows. + */ + @Parameter(required = true) + private boolean multiThreaded = false; + + /** + * Defines + */ + @Parameter + 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 + private String defineSet; + + /** + * Clears default defines + */ + @Parameter(required = true) + private boolean clearDefaultDefines; + + /** + * Undefines + */ + @Parameter + 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 + private String undefineSet; + + /** + * Clears default undefines + */ + @Parameter + private boolean clearDefaultUndefines; + + /** + * Include Paths. Defaults to "${sourceDirectory}/include" + */ + @Parameter + private List includePaths; + + /** + * Test Include Paths. Defaults to "${testSourceDirectory}/include" + */ + @Parameter + private List testIncludePaths; + + /** + * System Include Paths, which are added at the end of all include paths + */ + @Parameter + private List systemIncludePaths; + + /** + * Additional options for the C++ compiler Defaults to Architecture-OS-Linker + * specific values. FIXME table missing + */ + @Parameter + private List options; + + /** + * Additional options for the compiler when running in the nar-testCompile + * phase. + */ + @Parameter + private List testOptions; + + /** + * Options for the compiler as a whitespace separated list. Will work in + * combination with <options>. + */ + @Parameter + private String optionSet; + + /** + * Clears default options + */ + @Parameter(required = true) + private boolean clearDefaultOptions; + + /** + * Comma separated list of filenames to compile in order + */ + @Parameter + private String compileOrder; private AbstractCompileMojo mojo; 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 49757b5..152f160 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 @@ -26,7 +26,9 @@ */ public interface Executable { - boolean shouldRun(); + List/* */getArgs(); + String getBinding(NarArtifact dependency); - List/* */getArgs(); + boolean shouldRun(); + } 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 117463a..c5d8fc3 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 @@ -19,12 +19,14 @@ */ package com.github.maven_nar; +import java.util.List; + import org.apache.maven.plugin.MojoFailureException; public interface ITest extends Executable { public abstract String getName() throws MojoFailureException; - public abstract String getLink(); + public abstract String getLink(List libraries); } \ No newline at end of file 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 5486396..b032e1d 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 @@ -25,6 +25,8 @@ import java.util.ArrayList; import java.util.List; +import org.apache.maven.plugins.annotations.Parameter; + /** * Sets up a library to create * @@ -32,83 +34,79 @@ */ 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(); + /** + * Type of the library to generate. Possible choices are: "plugin", "shared", + * "static", "jni" or "executable". + * Defaults to "shared". + */ + @Parameter + private String type = SHARED; + + /** + * Type of subsystem to generate: "gui", "console", "other". Defaults to + * "console". + */ + @Parameter + private String subSystem = "console"; + + /** + * Link with stdcpp if necessary Defaults to true. + */ + @Parameter(defaultValue = "true") + private boolean linkCPP = true; + + /** + * Link with fortran runtime if necessary Defaults to false. + */ + @Parameter + private boolean linkFortran = false; + + /** + * Link with fortran startup, so that the gcc linker can find the "main" of + * fortran. Defaults to false. + */ + @Parameter + private boolean linkFortranMain = false; + + /** + * If specified will create the NarSystem class with methods to load a JNI + * library. + */ + @Parameter + private String narSystemPackage = null; + + /** + * Name of the NarSystem class + */ + @Parameter(defaultValue = "NarSystem", required = true) + private String narSystemName = "NarSystem"; + + /** + * The target directory into which to generate the output. + */ + @Parameter(defaultValue = "${project.build.dir}/nar/nar-generated", required = true) + private String narSystemDirectory = "nar-generated"; + + /** + * When true and if type is "executable" run this executable. Defaults to + * false; + */ + @Parameter + 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 + private List/* */args = new ArrayList(); + + /** + * List of artifact:binding for type of dependency to link against when there is a choice. + */ + @Parameter + private List dependencyBindings = new ArrayList(); /* * (non-Javadoc) @@ -143,6 +141,18 @@ public final boolean shouldRun() { return args; } + public String getBinding(NarArtifact dependency) { + for (String dependBind : dependencyBindings ) { + String[] pair = dependBind.trim().split( ":", 2 ); + if( dependency.getArtifactId().equals(pair[0].trim()) ){ + String result = pair[1].trim(); + if( !result.isEmpty() ) + return result; + } + } + return null; + } + public final String getNarSystemName() { return narSystemName; } 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 0b216c6..91161ce 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 @@ -38,6 +38,7 @@ import org.codehaus.plexus.util.FileUtils; import org.apache.maven.plugin.logging.Log; +import org.apache.maven.plugins.annotations.Parameter; /** * Linker tag @@ -46,115 +47,141 @@ */ 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; - - /** - * Additional options for the linker when running in the nar-testCompile phase. - * - * @parameter default-value="" - */ - private List testOptions; - - /** - * 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; + /** + * The Linker Some choices are: "msvc", "g++", "CC", "icpc", ... Default is + * Architecture-OS-Linker specific: FIXME: + * table missing + */ + @Parameter + private String name; + + /** + * The prefix for the linker. + */ + @Parameter + private String prefix; + + /** + * Path location of the linker tool + */ + @Parameter + private String toolPath; + + /** + * Enables or disables incremental linking. + */ + @Parameter(required = true) + private boolean incremental = false; + + /** + * Enables or disables the production of a map file. + */ + @Parameter(required = true) + private boolean map = false; + + @Parameter(required = true) + private boolean skipDepLink = false; + + /** + * Options for the linker Defaults to Architecture-OS-Linker specific values. + * FIXME table missing + */ + @Parameter + private List options; + + /** + * Additional options for the linker when running in the nar-testCompile + * phase. + * + */ + @Parameter + private List testOptions; + + /** + * Options for the linker as a whitespace separated list. Defaults to + * Architecture-OS-Linker specific values. Will + * work in combination with <options>. + */ + @Parameter + private String optionSet; + + /** + * Clears default options + */ + @Parameter(required = true) + private boolean clearDefaultOptions; + + /** + * Adds libraries to the linker. + */ + @Parameter + 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 + private String libSet; + + /** + * Adds system libraries to the linker. + */ + @Parameter + 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 + 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 + private String narDependencyLibOrder; + + /** + *

+ * Specifies to use Default link ordering of libraries that come from mvn dependency tree. + * The Default link order (generated by nar) is a Level-order tree traversing list (also called BFS) of + * dependency tree, given as a comma separated list of groupId:artifactId. + *

+ *

+ * default Value is "false" + *

+ */ + @Parameter(defaultValue = "false") + private boolean narDefaultDependencyLibOrder = false; + + /** + * Specifies that if using default dependency lib order then turn on/off logic that pushes + * dependencies to appropriate place in linker line based on transitive dependencies. + * @since 3.5.2 + */ + @Parameter(defaultValue = "false") + protected boolean pushDepsToLowestOrder = false; + + /** + * Specify that the linker should generate an intermediate manifest based on + * the inputs. + */ + @Parameter(property = "nar.generateManifest", defaultValue = "true") + private boolean generateManifest = true; private final Log log; 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 80e293c..5c78cd4 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 @@ -28,6 +28,8 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.shared.artifact.filter.collection.ScopeFilter; /** * Compiles native source files. @@ -41,6 +43,13 @@ */ public class NarCompileMojo extends AbstractCompileMojo { + /** + * Specify that the final manifest should be embedded in the output (default + * true) or false for side by side. + */ + @Parameter(property = "nar.embedManifest", defaultValue = "true") + protected boolean embedManifest = true; + /** * The current build session instance. * @@ -50,14 +59,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; - } + /** + * List the dependencies needed for compilation, those dependencies are used + * to get the include paths needed for + * compilation and to get the libraries paths and names needed for linking. + */ + @Override + protected ScopeFilter getArtifactScopeFilter() { + return new ScopeFilter(Artifact.SCOPE_COMPILE, null); + } + } 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 56a8c52..82738eb 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 @@ -27,6 +27,8 @@ import java.util.Set; import org.apache.maven.artifact.Artifact; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.shared.artifact.filter.collection.ScopeFilter; /** * Compiles native test source files. @@ -38,19 +40,22 @@ * @author Mark Donszelmann */ public class NarTestCompileMojo extends AbstractCompileMojo { - /** - * Skip running of NAR integration test plugins. - * - * @parameter property="skipNar" default-value="false" - */ - protected boolean skipNar; + /** + * Skip running of NAR integration test plugins. + */ + @Parameter(property = "skipNar") + protected boolean skipNar; + + /** + * List the dependencies needed for tests compilations, those dependencies are + * used to get the include paths needed + * for compilation and to get the libraries paths and names needed for + * linking. + */ + @Override + protected ScopeFilter getArtifactScopeFilter() { + // Was Artifact.SCOPE_TEST - runtime?? + return new ScopeFilter( Artifact.SCOPE_TEST, null ); + } - 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/Test.java b/com.github.sdedwards.m2e-nar/src/com/github/maven_nar/Test.java index 319b30e..4928841 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 @@ -26,6 +26,7 @@ import java.util.List; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Parameter; /** * Sets up a test to create @@ -34,36 +35,46 @@ */ 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 + */ + @Parameter(required = true) + 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 to main artifact used for this test. + * Possible choices are: "shared" or "static". + * Defaults to library type if single library is built or "shared" otherwise. + */ + @Parameter(defaultValue = "shared") + private String link = null; - /** - * When true run this test. Defaults to true; - * - * @parameter expresssion="" - */ - private boolean run = true; + /** + * When true run this test. Defaults to true; + */ + @Parameter(defaultValue = "true") + 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(); + /** + * Type of the library to generate. + * Possible choices are: "shared", "static" or "executable". + * Defaults to "executable". + */ + @Parameter + private String type = Library.EXECUTABLE; + + /** + * Arguments to be used for running this test. Defaults to empty list. This + * option is only used if run=true. + */ + @Parameter + private List/* */args = new ArrayList(); + + /** + * List of artifact:binding for type of dependency to link against when there is a choice. + */ + @Parameter + private List dependencyBindings = new ArrayList(); public final String getName() throws MojoFailureException { if (name == null) { @@ -72,15 +83,38 @@ public final String getName() throws MojoFailureException { return name; } - public final String getLink() { - return link; - } - + public final String getLink( List libraries ) { + if( this.link != null ) + return this.link; + + String libraryPreferred = null; + if(libraries.size() == 1){ + String type = libraries.get(0).getType(); + if (Library.SHARED.equals(type)||Library.STATIC.equals(type) ) + libraryPreferred = type; + //if(Library.JNI.equals(type)) default shared + } + return libraryPreferred == null ? Library.SHARED : libraryPreferred; + } + public final boolean shouldRun() { return run; } - public final List/* */getArgs() { - return args; - } + @Override + public final List/* */getArgs() { + return this.args; + } + + public String getBinding(NarArtifact dependency) { + for (String dependBind : dependencyBindings ) { + String[] pair = dependBind.trim().split( ":", 2 ); // TODO: match how much? + if( dependency.getArtifactId().equals(pair[0].trim()) ){ + String result = pair[1].trim(); + if( !result.isEmpty() ) + return result; + } + } + return null; + } }