[prev in list] [next in list] [prev in thread] [next in thread]
List: httpcomponents-commits
Subject: svn commit: r1026476 - in /httpcomponents/maven-notice-plugin: ./ trunk/
From: olegk () apache ! org
Date: 2010-10-22 20:14:31
Message-ID: 20101022201431.948062388978 () eris ! apache ! org
[Download RAW message or body]
Author: olegk
Date: Fri Oct 22 20:14:30 2010
New Revision: 1026476
URL: http://svn.apache.org/viewvc?rev=1026476&view=rev
Log:
Maven plugin for generation of NOTICE and LICENSE resources
Added:
httpcomponents/maven-notice-plugin/
httpcomponents/maven-notice-plugin/trunk/
httpcomponents/maven-notice-plugin/trunk/pom.xml (with props)
httpcomponents/maven-notice-plugin/trunk/src/
httpcomponents/maven-notice-plugin/trunk/src/main/
httpcomponents/maven-notice-plugin/trunk/src/main/java/
httpcomponents/maven-notice-plugin/trunk/src/main/java/org/
httpcomponents/maven-notice-plugin/trunk/src/main/java/org/apache/
httpcomponents/maven-notice-plugin/trunk/src/main/java/org/apache/httpcomponents/
httpcomponents/maven-notice-plugin/trunk/src/main/java/org/apache/httpcomponents/maven/
httpcomponents/maven-notice-plugin/trunk/src/main/java/org/apache/httpcomponents/maven/plugin/
httpcomponents/maven-notice-plugin/trunk/src/main/java/org/apache/httpcomponents/maven/plugin/notice/
httpcomponents/maven-notice-plugin/trunk/src/main/java/org/apache/httpcomponents/maven/plugin/notice/NoticeMojo.java \
(with props)
Added: httpcomponents/maven-notice-plugin/trunk/pom.xml
URL: http://svn.apache.org/viewvc/httpcomponents/maven-notice-plugin/trunk/pom.xml?rev=1026476&view=auto
==============================================================================
--- httpcomponents/maven-notice-plugin/trunk/pom.xml (added)
+++ httpcomponents/maven-notice-plugin/trunk/pom.xml Fri Oct 22 20:14:30 2010
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ====================================================================
+ 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.
+ ====================================================================
+
+ This software consists of voluntary contributions made by many
+ individuals on behalf of the Apache Software Foundation. For more
+ information on the Apache Software Foundation, please see
+ <http://www.apache.org />.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" \
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" \
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 \
http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>maven-notice-plugin</artifactId>
+ <name>Maven NOTICE and LICENCE plugin</name>
+ <version>0.0.1-SNAPSHOT</version>
+ <description>Maven plugin for automatic generation of NOTICE and LICENCE \
resources</description> + <url>http://hc.apache.org/</url>
+ <inceptionYear>2010</inceptionYear>
+ <packaging>maven-plugin</packaging>
+
+ <organization>
+ <name>Apache Software Foundation</name>
+ <url>http://www.apache.org/</url>
+ </organization>
+
+ <licenses>
+ <license>
+ <name>Apache License</name>
+ <url>LICENSE.txt</url>
+ <distribution>repo</distribution>
+ </license>
+ </licenses>
+
+ <scm>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/httpcomponents/maven-notice-plugin/trunk</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/httpcomponents/maven-notice-plugin/trunk</developerConnection>
+ <url>http://svn.apache.org/repos/asf/httpcomponents/maven-notice-plugin/trunk</url>
+ </scm>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+ <maven.version>2.2.0</maven.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>${maven.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-project</artifactId>
+ <version>${maven.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-source-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>attach-sources</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
Propchange: httpcomponents/maven-notice-plugin/trunk/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/maven-notice-plugin/trunk/pom.xml
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/maven-notice-plugin/trunk/pom.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: httpcomponents/maven-notice-plugin/trunk/src/main/java/org/apache/httpcomponents/maven/plugin/notice/NoticeMojo.java
URL: http://svn.apache.org/viewvc/httpcomponents/maven-notice-plugin/trunk/src/main/ja \
va/org/apache/httpcomponents/maven/plugin/notice/NoticeMojo.java?rev=1026476&view=auto
==============================================================================
--- httpcomponents/maven-notice-plugin/trunk/src/main/java/org/apache/httpcomponents/maven/plugin/notice/NoticeMojo.java \
(added)
+++ httpcomponents/maven-notice-plugin/trunk/src/main/java/org/apache/httpcomponents/maven/plugin/notice/NoticeMojo.java \
Fri Oct 22 20:14:30 2010 @@ -0,0 +1,159 @@
+/*
+ * ====================================================================
+ *
+ * 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.httpcomponents.maven.plugin.notice;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.List;
+
+import org.apache.maven.model.License;
+import org.apache.maven.model.Resource;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+
+/**
+ * @phase generate-resources
+ * @goal generate
+ */
+public final class NoticeMojo extends AbstractMojo {
+
+ /**
+ * The Maven Project Object
+ *
+ * @parameter expression="${project}"
+ * @required
+ */
+ protected MavenProject project;
+
+ /**
+ * This is where build results go.
+ *
+ * @parameter default-value="${project.build.directory}"
+ * @required
+ * @readonly
+ */
+ private File directory;
+
+ public NoticeMojo() {
+ super();
+ this.project = new MavenProject();
+ }
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ if (!this.project.getPackaging().equalsIgnoreCase("jar")) {
+ return;
+ }
+ getLog().info("Generating NOTICE and LICENSE resources");
+
+ File nalDir = new File(this.directory, "notice-and-license");
+ if (!nalDir.exists()) {
+ nalDir.mkdirs();
+ }
+
+ List licenses = this.project.getLicenses();
+ for (int i = 0; i < licenses.size(); i++) {
+ License license = (License) licenses.get(i);
+ URI uri = createURI(license.getUrl());
+ if (!uri.isAbsolute()) {
+ File file = findFile(license.getUrl());
+ if (file != null) {
+ uri = createURI("file://" + file.getAbsolutePath());
+ }
+ }
+ String s = "LICENSE";
+ if (i > 0) {
+ s = s + i;
+ }
+ s = s + ".txt";
+ File out = new File(nalDir, s);
+ copy(uri, out);
+ }
+ File file = findFile("NOTICE.txt");
+ if (file != null) {
+ File out = new File(nalDir, "NOTICE.txt");
+ URI uri = createURI("file://" + file.getAbsolutePath());
+ copy(uri, out);
+ }
+
+ Resource nalRes = new Resource();
+ nalRes.setDirectory(nalDir.getAbsolutePath());
+ nalRes.setFiltering(false);
+ nalRes.setTargetPath("META-INF");
+ this.project.addResource(nalRes);
+ this.project.addTestResource(nalRes);
+ }
+
+ private File findFile(final String resource) {
+ MavenProject current = this.project;
+ while (current != null) {
+ File basedir = current.getBasedir();
+ File file = new File(basedir, resource);
+ if (file.exists()) {
+ return file;
+ }
+ current = current.getParent();
+ }
+ return null;
+ }
+
+ private URI createURI(final String s) throws MojoExecutionException {
+ try {
+ return new URI(s);
+ } catch (URISyntaxException ex) {
+ throw new MojoExecutionException("Invalid URL: " + s);
+ }
+ }
+
+ private void copy(final URI in, final File out) throws MojoExecutionException {
+ try {
+ InputStream instream = in.toURL().openStream();
+ try {
+ OutputStream outstream = new FileOutputStream(out);
+ try {
+ byte[] tmp = new byte[1024 * 8];
+ int l;
+ while ((l = instream.read(tmp)) != -1) {
+ outstream.write(tmp, 0, l);
+ }
+ } finally {
+ outstream.close();
+ }
+ } finally {
+ instream.close();
+ }
+ } catch (IOException ex) {
+ throw new MojoExecutionException("I/O error: " + ex.getMessage(), ex);
+ }
+ }
+
+}
Propchange: httpcomponents/maven-notice-plugin/trunk/src/main/java/org/apache/httpcomponents/maven/plugin/notice/NoticeMojo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/maven-notice-plugin/trunk/src/main/java/org/apache/httpcomponents/maven/plugin/notice/NoticeMojo.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/maven-notice-plugin/trunk/src/main/java/org/apache/httpcomponents/maven/plugin/notice/NoticeMojo.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic