Author: aadamchik
Date: Sun Dec 24 14:44:01 2006
New Revision: 490078
URL: http://svn.apache.org/viewvc?view=rev&rev=490078
Log:
CAY-719:Finalize Maven assembly scripts for the upcoming 3.0 milestone releases
(added filtering capabilities)
Added:
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/PatternGroup.java
Modified:
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/AbstractAggregatorMojo.java
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/BinAggregatorMojo.java
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/JavadocsAggregatorMojo.java
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/SourcesAggregatorMojo.java
Modified:
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/AbstractAggregatorMojo.java
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/AbstractAggregatorMojo.java?view=diff&rev=490078&r1=490077&r2=490078
==============================================================================
---
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/AbstractAggregatorMojo.java
(original)
+++
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/AbstractAggregatorMojo.java
Sun Dec 24 14:44:01 2006
@@ -108,7 +108,7 @@
protected MavenProject project;
protected abstract File getUnpackDirectory();
-
+
/**
* Preprocesses the list of ArtifactItems. This method defaults the
outputDirectory if
* not set and creates the output Directory if it doesn't exist.
@@ -122,12 +122,12 @@
Iterator iter = artifactItems.iterator();
while (iter.hasNext()) {
ArtifactItem artifactItem = (ArtifactItem) iter.next();
- this.getLog().info("Configured Artifact: " +
artifactItem.toString());
+ getLog().debug("Configured artifact: " + artifactItem.toString());
if (artifactItem.getOutputDirectory() == null) {
artifactItem.setOutputDirectory(getUnpackDirectory());
}
-
+
artifactItem.getOutputDirectory().mkdirs();
}
return artifactItems;
Modified:
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/BinAggregatorMojo.java
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/BinAggregatorMojo.java?view=diff&rev=490078&r1=490077&r2=490078
==============================================================================
---
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/BinAggregatorMojo.java
(original)
+++
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/BinAggregatorMojo.java
Sun Dec 24 14:44:01 2006
@@ -1,20 +1,22 @@
package org.apache.cayenne.maven.plugin.aggregator;
import java.io.File;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
+import org.apache.maven.archiver.MavenArchiveConfiguration;
+import org.apache.maven.archiver.MavenArchiver;
import org.apache.maven.plugin.MojoExecutionException;
-import org.codehaus.plexus.archiver.Archiver;
-import org.codehaus.plexus.archiver.ArchiverException;
+import org.codehaus.plexus.archiver.jar.JarArchiver;
import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
/**
- * A goal to build aggregated jar artifacts from multiple "standard" artifacts.
+ * A goal to build aggregated jar artifacts from multiple other artifacts.
*
* @author Andrus Adamchik
* @goal aggregate-bin
+ * @phase package
+ * @requiresProject
*/
public class BinAggregatorMojo extends AbstractAggregatorMojo {
@@ -22,10 +24,6 @@
"META-INF/maven/**"
};
- static final String[] DEFAULT_INCLUDES = new String[] {
- "**/**"
- };
-
/**
* Default location used for mojo unless overridden in ArtifactItem
*
@@ -43,6 +41,20 @@
*/
private String finalName;
+ /**
+ * A file that contains excludes patterns.
+ *
+ * @parameter
+ */
+ private File excludesFile;
+
+ /**
+ * A file that contains includes patterns.
+ *
+ * @parameter
+ */
+ private File includesFile;
+
protected File getUnpackDirectory() {
return unpackDirectory;
}
@@ -55,38 +67,59 @@
unpackArtifact(artifactItem);
}
- packArtifact();
+ File file = packArtifact();
+ getLog().warn("created jar " + file.getAbsolutePath());
+ project.getArtifact().setFile(file);
}
- private void packArtifact() throws MojoExecutionException {
- // pack...
+ private File packArtifact() throws MojoExecutionException {
+
File outputDirectory = new File(project.getBuild().getDirectory());
File destinationFile = new File(outputDirectory, finalName + ".jar");
- Archiver archiver;
+ JarArchiver jarArchiver;
try {
- archiver = archiverManager.getArchiver("jar");
+ jarArchiver = (JarArchiver) archiverManager.getArchiver("jar");
}
catch (NoSuchArchiverException e) {
throw new MojoExecutionException("Unknown archiver type", e);
}
+ PatternGroup excludes = new PatternGroup(excludesFile);
+ excludes.addPatterns(DEFAULT_EXCLUDES);
+
+ PatternGroup includes = new PatternGroup(includesFile);
+ if (includes.size() == 0) {
+ includes.addPatterns(new String[] {
+ "**/**"
+ });
+ }
+
+ // MavenArchiver adds Maven stuff into META-INF
+ MavenArchiver archiver = new MavenArchiver();
+ archiver.setArchiver(jarArchiver);
+ archiver.setOutputFile(destinationFile);
+
+ MavenArchiveConfiguration archive = new MavenArchiveConfiguration();
+
try {
- archiver.setDestFile(destinationFile);
- archiver.addDirectory(
- getUnpackDirectory(),
- DEFAULT_INCLUDES,
- DEFAULT_EXCLUDES);
- archiver.createArchive();
- }
- catch (ArchiverException e) {
- throw new MojoExecutionException("Error creating archive", e);
+ File contentDirectory = getUnpackDirectory();
+ if (!contentDirectory.exists()) {
+ getLog().warn("JAR will be empty - no content was marked for
inclusion!");
+ }
+ else {
+ archiver.getArchiver().addDirectory(
+ contentDirectory,
+ includes.getPatterns(),
+ excludes.getPatterns());
+ }
+
+ archiver.createArchive(project, archive);
}
- catch (IOException e) {
- throw new MojoExecutionException("IO Error creating archive", e);
+ catch (Exception e) {
+ throw new MojoExecutionException("Error assembling JAR", e);
}
- // make it a project artifact
- project.getArtifact().setFile(destinationFile);
+ return destinationFile;
}
}
Modified:
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/JavadocsAggregatorMojo.java
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/JavadocsAggregatorMojo.java?view=diff&rev=490078&r1=490077&r2=490078
==============================================================================
---
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/JavadocsAggregatorMojo.java
(original)
+++
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/JavadocsAggregatorMojo.java
Sun Dec 24 14:44:01 2006
@@ -24,7 +24,7 @@
import org.apache.maven.plugin.MojoFailureException;
/**
- * A goal to build aggregated javadocs artifacts from multiple "standard"
artifacts.
+ * A goal to build an aggregated javadocs artifact from multiple source
artifacts.
*
* @author Andrus Adamchik
* @goal aggregate-javadocs
@@ -45,5 +45,6 @@
}
public void execute() throws MojoExecutionException, MojoFailureException {
+ // TODO
}
}
Added:
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/PatternGroup.java
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/PatternGroup.java?view=auto&rev=490078
==============================================================================
---
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/PatternGroup.java
(added)
+++
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/PatternGroup.java
Sun Dec 24 14:44:01 2006
@@ -0,0 +1,92 @@
+/*****************************************************************
+ * 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.
+ ****************************************************************/
+package org.apache.cayenne.maven.plugin.aggregator;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.apache.maven.plugin.MojoExecutionException;
+
+public class PatternGroup {
+
+ protected Collection patterns;
+
+ static Collection parsePatterns(File patternsFile) throws
MojoExecutionException {
+ Collection patterns = new ArrayList();
+
+ if (patternsFile == null || !patternsFile.isFile()) {
+ return patterns;
+ }
+
+ BufferedReader in;
+ try {
+ in = new BufferedReader(new FileReader(patternsFile));
+ }
+ catch (FileNotFoundException e) {
+ throw new MojoExecutionException("Error reading patterns file "
+ + patternsFile, e);
+ }
+
+ try {
+ String line;
+ while ((line = in.readLine()) != null) {
+ patterns.add(line);
+ }
+ }
+ catch (IOException e) {
+ throw new MojoExecutionException("Error reading patterns file "
+ + patternsFile, e);
+ }
+ finally {
+ try {
+ in.close();
+ }
+ catch (IOException ioex) {
+ }
+ }
+
+ return patterns;
+ }
+
+ public PatternGroup(Collection patterns) {
+ this.patterns = patterns;
+ }
+
+ public PatternGroup(File patternsFile) throws MojoExecutionException {
+ this(parsePatterns(patternsFile));
+ }
+
+ public void addPatterns(String[] patterns) {
+ this.patterns.addAll(Arrays.asList(patterns));
+ }
+
+ public String[] getPatterns() {
+ return (String[]) patterns.toArray(new String[patterns.size()]);
+ }
+
+ public int size() {
+ return patterns.size();
+ }
+}
Modified:
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/SourcesAggregatorMojo.java
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/SourcesAggregatorMojo.java?view=diff&rev=490078&r1=490077&r2=490078
==============================================================================
---
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/SourcesAggregatorMojo.java
(original)
+++
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/SourcesAggregatorMojo.java
Sun Dec 24 14:44:01 2006
@@ -24,7 +24,7 @@
import org.apache.maven.plugin.MojoFailureException;
/**
- * A goal to build aggregated sources artifacts from multiple "standard"
artifacts.
+ * A goal to build an aggregated source artifact from multiple source
artifacts.
*
* @author Andrus Adamchik
* @goal aggregate-sources
@@ -45,5 +45,6 @@
}
public void execute() throws MojoExecutionException, MojoFailureException {
+ // TODO
}
}