[Git][java-team/properties-maven-plugin][master] 10 commits: Standards-Version updated to 4.6.1
Emmanuel Bourg (@ebourg)
gitlab at salsa.debian.org
Tue Dec 6 15:22:19 GMT 2022
Emmanuel Bourg pushed to branch master at Debian Java Maintainers / properties-maven-plugin
Commits:
b5a8a867 by Emmanuel Bourg at 2022-12-06T15:51:11+01:00
Standards-Version updated to 4.6.1
- - - - -
a2b16743 by Emmanuel Bourg at 2022-12-06T15:51:16+01:00
Switch to debhelper level 13
- - - - -
cc6f33bf by Emmanuel Bourg at 2022-12-06T15:51:58+01:00
Remove constraints unnecessary since buster (oldstable)
* Build-Depends: Drop versioned constraint on maven-debian-helper (>= 1.5).
Changes-By: deb-scrub-obsolete
- - - - -
242b0c7a by Emmanuel Bourg at 2022-12-06T15:52:46+01:00
Removed the unused packaging files
- - - - -
59b07111 by Emmanuel Bourg at 2022-12-06T15:55:18+01:00
Filter out the Maven wrapper from the upstream tarball
- - - - -
a151fa4b by Emmanuel Bourg at 2022-12-06T15:55:28+01:00
New upstream version 1.1.0
- - - - -
c90c5c94 by Emmanuel Bourg at 2022-12-06T15:55:28+01:00
Update upstream source from tag 'upstream/1.1.0'
Update to upstream version '1.1.0'
with Debian dir 67375f3e177adaedb19ed8c782ed03a69b1381a8
- - - - -
2da00929 by Emmanuel Bourg at 2022-12-06T16:00:33+01:00
Refreshed the patch
- - - - -
e555a7a8 by Emmanuel Bourg at 2022-12-06T16:05:42+01:00
Updated the Maven rules
- - - - -
3772eb64 by Emmanuel Bourg at 2022-12-06T16:05:52+01:00
Upload to unstable
- - - - -
28 changed files:
- .gitignore
- − .travis.yml
- README.md
- debian/changelog
- − debian/compat
- debian/control
- debian/copyright
- − debian/libproperties-maven-plugin-java-doc.doc-base.api
- − debian/libproperties-maven-plugin-java-doc.install
- − debian/maven.cleanIgnoreRules
- debian/maven.ignoreRules
- − debian/maven.publishedRules
- debian/maven.rules
- debian/patches/01-plexus-component-metadata.patch
- pom.xml
- + src/it/settings.xml
- + src/it/write-project/invoker.properties
- + src/it/write-project/pom.xml
- + src/it/write-project/verify.groovy
- src/main/java/org/codehaus/mojo/properties/AbstractWritePropertiesMojo.java
- src/main/java/org/codehaus/mojo/properties/CircularDefinitionPreventer.java
- src/main/java/org/codehaus/mojo/properties/ReadPropertiesMojo.java
- src/main/java/org/codehaus/mojo/properties/SetSystemPropertiesMojo.java
- src/main/java/org/codehaus/mojo/properties/WriteActiveProfileProperties.java
- src/main/java/org/codehaus/mojo/properties/WriteProjectProperties.java
- src/site/apt/usage.apt.vm
- src/test/java/org/codehaus/mojo/properties/PropertyResolverTest.java
- + src/test/java/org/codehaus/mojo/properties/ReadPropertiesMojoTest.java
Changes:
=====================================
.gitignore
=====================================
@@ -2,3 +2,6 @@ target
.settings
.project
.classpath
+*.iml
+/.idea/
+/.factorypath
=====================================
.travis.yml deleted
=====================================
@@ -1,15 +0,0 @@
-language: java
-jdk:
- - openjdk6
- - oraclejdk7
- - oraclejdk8
-script: "mvn --show-version --errors --batch-mode clean verify"
-cache:
- directories:
- - $HOME/.m2
-branches:
- except:
- - gh-pages
-notifications:
- email:
- - khmarbaise at apache.org
=====================================
README.md
=====================================
@@ -1,7 +1,8 @@
# MojoHaus Properties Maven Plugin
This is the [properties-maven-plugin](http://www.mojohaus.org/properties-maven-plugin/).
-
+
+[![Maven Central](https://img.shields.io/maven-central/v/org.codehaus.mojo/properties-maven-plugin.svg?label=Maven%20Central)](https://search.maven.org/artifact/org.codehaus.mojo/properties-maven-plugin)
[![Build Status](https://travis-ci.org/mojohaus/properties-maven-plugin.svg?branch=master)](https://travis-ci.org/mojohaus/properties-maven-plugin)
## Releasing
=====================================
debian/changelog
=====================================
@@ -1,3 +1,16 @@
+properties-maven-plugin (1.1.0-1) unstable; urgency=medium
+
+ * Team upload.
+ * New upstream release
+ - Refreshed the patch
+ - Updated the Maven rules
+ * Standards-Version updated to 4.6.1
+ * Switch to debhelper level 13
+ * Remove constraints unnecessary since buster (oldstable)
+ * Filter out the Maven wrapper from the upstream tarball
+
+ -- Emmanuel Bourg <ebourg at apache.org> Tue, 06 Dec 2022 16:05:47 +0100
+
properties-maven-plugin (1.0.0-2) unstable; urgency=medium
* Team upload.
=====================================
debian/compat deleted
=====================================
@@ -1 +0,0 @@
-11
=====================================
debian/control
=====================================
@@ -4,15 +4,15 @@ Priority: optional
Maintainer: Debian Java Maintainers <pkg-java-maintainers at lists.alioth.debian.org>
Uploaders: Steffen Moeller <moeller at debian.org>
Build-Depends:
- debhelper (>= 11),
+ debhelper-compat (= 13),
default-jdk,
junit4,
libmaven-plugin-tools-java,
libmaven3-core-java,
libplexus-component-metadata-java,
libplexus-utils-java,
- maven-debian-helper (>= 1.5)
-Standards-Version: 4.2.1
+ maven-debian-helper
+Standards-Version: 4.6.1
Vcs-Git: https://salsa.debian.org/java-team/properties-maven-plugin.git
Vcs-Browser: https://salsa.debian.org/java-team/properties-maven-plugin
Homepage: http://www.mojohaus.org/properties-maven-plugin/
=====================================
debian/copyright
=====================================
@@ -1,6 +1,9 @@
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: Properties Maven Plugin
Source: https://github.com/mojohaus/properties-maven-plugin
+Files-Excluded: .mvn/*
+ mvnw*
+ .github/*
Files: *
Copyright: 2009-2013, Zarar Siddiqi <zarars at gmail.com>
=====================================
debian/libproperties-maven-plugin-java-doc.doc-base.api deleted
=====================================
@@ -1,10 +0,0 @@
-Document: libproperties-maven-plugin-java
-Title: API Javadoc for Properties Maven Plugin
-Author: Properties Maven Plugin developers
-Abstract: This is the API Javadoc provided for the
- libproperties-maven-plugin-java library.
-Section: Programming
-
-Format: HTML
-Index: /usr/share/doc/libproperties-maven-plugin-java/api/index.html
-Files: /usr/share/doc/libproperties-maven-plugin-java/api/*
=====================================
debian/libproperties-maven-plugin-java-doc.install deleted
=====================================
@@ -1 +0,0 @@
-target/apidocs/* usr/share/doc/libproperties-maven-plugin-java/api
=====================================
debian/maven.cleanIgnoreRules deleted
=====================================
@@ -1 +0,0 @@
-
=====================================
debian/maven.ignoreRules
=====================================
@@ -1,2 +1 @@
-org.codehaus.plexus plexus-maven-plugin
=====================================
debian/maven.publishedRules deleted
=====================================
@@ -1 +0,0 @@
-
=====================================
debian/maven.rules
=====================================
@@ -1,5 +1,7 @@
junit junit jar s/.*/4.x/ * *
-org.apache.maven maven-model * s/.*/3.x/ * *
-org.apache.maven maven-plugin-api * s/.*/3.x/ * *
-org.apache.maven s/maven-project/maven-core/ * s/.*/3.x/ * *
+org.apache.maven maven-artifact * s/.*/3.x/ * *
+org.apache.maven maven-core * s/.*/3.x/ * *
+org.apache.maven maven-model * s/.*/3.x/ * *
+org.apache.maven maven-model-builder * s/.*/3.x/ * *
+org.apache.maven maven-plugin-api * s/.*/3.x/ * *
=====================================
debian/patches/01-plexus-component-metadata.patch
=====================================
@@ -3,10 +3,12 @@ Author: Emmanuel Bourg <ebourg at apache.org>
Forwarded: no
--- a/pom.xml
+++ b/pom.xml
-@@ -156,6 +156,18 @@
- </execution>
- </executions>
- </plugin>
+@@ -142,6 +142,24 @@
+
+ </dependencies>
+
++ <build>
++ <plugins>
+ <plugin>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-component-metadata</artifactId>
@@ -19,6 +21,10 @@ Forwarded: no
+ </execution>
+ </executions>
+ </plugin>
- </plugins>
- </build>
- </project>
++ </plugins>
++ </build>
++
++
+ <profiles>
+ <profile>
+ <id>run-its</id>
=====================================
pom.xml
=====================================
@@ -22,16 +22,15 @@
<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/xsd/maven-4.0.0.xsd">
<parent>
- <artifactId>mojo-parent</artifactId>
<groupId>org.codehaus.mojo</groupId>
- <version>38</version>
+ <artifactId>mojo-parent</artifactId>
+ <version>65</version>
</parent>
<modelVersion>4.0.0</modelVersion>
- <groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
- <version>1.0.0</version>
+ <version>1.1.0</version>
<name>Properties Maven Plugin</name>
<description>
@@ -53,14 +52,10 @@
</license>
</licenses>
- <prerequisites>
- <maven>2.2.1</maven>
- </prerequisites>
-
<properties>
- <maven.api.version>2.2.1</maven.api.version>
- <mojo.java.target>1.5</mojo.java.target>
+ <mavenVersion>3.2.5</mavenVersion>
<scmpublish.content>target/staging/${project.artifactId}</scmpublish.content>
+ <project.build.outputTimestamp>2022-03-19T15:52:49Z</project.build.outputTimestamp>
</properties>
@@ -68,15 +63,15 @@
<connection>scm:git:https://github.com/mojohaus/properties-maven-plugin.git</connection>
<developerConnection>scm:git:ssh://git@github.com/mojohaus/properties-maven-plugin.git</developerConnection>
<url>https://github.com/mojohaus/properties-maven-plugin</url>
- <tag>properties-maven-plugin-1.0.0</tag>
+ <tag>properties-maven-plugin-1.1.0</tag>
</scm>
<issueManagement>
<system>GitHub</system>
<url>https://github.com/mojohaus/properties-maven-plugin/issues/</url>
</issueManagement>
<ciManagement>
- <system>Travis-CI</system>
- <url>https://travis-ci.org/mojohaus/properties-maven-plugin</url>
+ <system>GitHub</system>
+ <url>https://github.com/mojohaus/properties-maven-plugin/actions/</url>
</ciManagement>
<developers>
@@ -101,21 +96,37 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
- <version>${maven.api.version}</version>
+ <version>${mavenVersion}</version>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
- <artifactId>maven-plugin-api</artifactId>
+ <artifactId>maven-model-builder</artifactId>
+ <version>${mavenVersion}</version>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
- <artifactId>maven-project</artifactId>
- <version>${maven.api.version}</version>
+ <artifactId>maven-artifact</artifactId>
+ <version>${mavenVersion}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <version>${mavenVersion}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>${mavenVersion}</version>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
- <version>3.0.22</version>
+ <version>3.4.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
@@ -131,31 +142,43 @@
</dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-plugin-plugin</artifactId>
- <executions>
- <execution>
- <id>mojo-descriptor</id>
- <goals>
- <goal>descriptor</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus-maven-plugin</artifactId>
- <executions>
- <execution>
- <goals>
- <goal>descriptor</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
+ <profiles>
+ <profile>
+ <id>run-its</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-invoker-plugin</artifactId>
+ <configuration>
+ <addTestClassPath>true</addTestClassPath>
+ <debug>true</debug>
+ <localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
+ <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
+ <projectsDirectory>src/it</projectsDirectory>
+ <showVersion>true</showVersion>
+ <setupIncludes>
+ <setupInclude>setup/pom.xml</setupInclude>
+ </setupIncludes>
+ <pomIncludes>
+ <pomInclude>*/pom.xml</pomInclude>
+ </pomIncludes>
+ <preBuildHookScript>setup</preBuildHookScript>
+ <postBuildHookScript>verify</postBuildHookScript>
+ <settingsFile>src/it/settings.xml</settingsFile>
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>install</goal>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
</project>
=====================================
src/it/settings.xml
=====================================
@@ -0,0 +1,63 @@
+<?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.
+-->
+
+<settings>
+ <mirrors>
+ <mirror>
+ <id>it-repo</id>
+ <name>RPM</name>
+ <url>@localRepositoryUrl@</url>
+ <mirrorOf>*</mirrorOf>
+ </mirror>
+ </mirrors>
+ <profiles>
+ <profile>
+ <id>it-repo</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <repositories>
+ <repository>
+ <id>local.central</id>
+ <url>@localRepositoryUrl@</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+ <pluginRepositories>
+ <pluginRepository>
+ <id>local.central</id>
+ <url>@localRepositoryUrl@</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </pluginRepository>
+ </pluginRepositories>
+ </profile>
+ </profiles>
+</settings>
=====================================
src/it/write-project/invoker.properties
=====================================
@@ -0,0 +1 @@
+invoker.goals = clean generate-resources
\ No newline at end of file
=====================================
src/it/write-project/pom.xml
=====================================
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.codehaus.mojo.properties.it</groupId>
+ <artifactId>write-project</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+
+ <properties>
+ <g>${groupId}</g>
+ <a>${artifactId}</a>
+ <v>${version}</v>
+ <properties-maven-plugin.version>@project.version@</properties-maven-plugin.version>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>properties-maven-plugin</artifactId>
+ <version>@project.version@</version>
+ <executions>
+ <execution>
+ <phase>generate-resources</phase>
+ <goals>
+ <goal>write-project-properties</goal>
+ </goals>
+ <configuration>
+ <outputFile>${project.build.outputDirectory}/project.properties</outputFile>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
=====================================
src/it/write-project/verify.groovy
=====================================
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+File prop = new File( basedir, 'target/classes/project.properties' )
+assert prop.exists()
+
+String content = prop.getText()
+assert content.startsWith( "#Properties" )
+assert !content.substring( 1 ).contains( '#' ) // check no timestamp comment, that starts with #
=====================================
src/main/java/org/codehaus/mojo/properties/AbstractWritePropertiesMojo.java
=====================================
@@ -1,5 +1,7 @@
package org.codehaus.mojo.properties;
+import java.io.BufferedReader;
+
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -23,6 +25,13 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
import java.util.Properties;
/*
@@ -51,7 +60,6 @@ import org.apache.maven.project.MavenProject;
/**
* @author <a href="mailto:zarars at gmail.com">Zarar Siddiqi</a>
- * @version $Id$
*/
public abstract class AbstractWritePropertiesMojo
extends AbstractMojo
@@ -71,31 +79,49 @@ public abstract class AbstractWritePropertiesMojo
protected void writeProperties( Properties properties, File file )
throws MojoExecutionException
{
- FileOutputStream fos = null;
try
{
- fos = new FileOutputStream( file );
- properties.store( fos, "Properties" );
+ storeWithoutTimestamp( properties, file, "Properties" );
}
catch ( FileNotFoundException e )
{
- getLog().error( "Could not create FileOutputStream: " + fos );
+ getLog().error( "Could not create FileOutputStream: " + file );
throw new MojoExecutionException( e.getMessage(), e );
}
catch ( IOException e )
{
- getLog().error( "Error writing properties: " + fos );
+ getLog().error( "Error writing properties: " + file );
throw new MojoExecutionException( e.getMessage(), e );
}
+ }
- try
- {
- fos.close();
- }
- catch ( IOException e )
+ // https://github.com/apache/maven-archiver/blob/master/src/main/java/org/apache/maven/archiver/PomPropertiesUtil.java#L81
+ private void storeWithoutTimestamp( Properties properties, File outputFile, String comments )
+ throws IOException
+ {
+ try ( PrintWriter pw = new PrintWriter( outputFile, "ISO-8859-1" ); StringWriter sw = new StringWriter() )
{
- getLog().error( "Error closing FileOutputStream: " + fos );
- throw new MojoExecutionException( e.getMessage(), e );
+ properties.store( sw, comments );
+ comments = '#' + comments;
+
+ List<String> lines = new ArrayList<>();
+ try ( BufferedReader r = new BufferedReader( new StringReader( sw.toString() ) ) )
+ {
+ String line;
+ while ( ( line = r.readLine() ) != null )
+ {
+ if ( !line.startsWith( "#" ) || line.equals( comments ) )
+ {
+ lines.add( line );
+ }
+ }
+ }
+
+ Collections.sort( lines );
+ for ( String l : lines )
+ {
+ pw.println( l );
+ }
}
}
=====================================
src/main/java/org/codehaus/mojo/properties/CircularDefinitionPreventer.java
=====================================
@@ -40,9 +40,9 @@ class CircularDefinitionPreventer
}
}
- private final List<VisitedProperty> entriesVisited = new LinkedList<VisitedProperty>();
+ private final List<VisitedProperty> entriesVisited = new LinkedList<>();
- private final Set<String> keysUsed = new HashSet<String>();
+ private final Set<String> keysUsed = new HashSet<>();
/**
* @param key The key.
=====================================
src/main/java/org/codehaus/mojo/properties/ReadPropertiesMojo.java
=====================================
@@ -45,9 +45,8 @@ import org.codehaus.plexus.util.cli.CommandLineUtils;
*
* @author <a href="mailto:zarars at gmail.com">Zarar Siddiqi</a>
* @author <a href="mailto:Krystian.Nowak at gmail.com">Krystian Nowak</a>
- * @version $Id$
*/
- at Mojo( name = "read-project-properties", defaultPhase = LifecyclePhase.NONE, requiresProject = true, threadSafe = true )
+ at Mojo( name = "read-project-properties", defaultPhase = LifecyclePhase.NONE, threadSafe = true )
public class ReadPropertiesMojo
extends AbstractMojo
{
@@ -108,6 +107,18 @@ public class ReadPropertiesMojo
@Parameter( defaultValue = "false" )
private boolean quiet;
+ /**
+ * Prefix that will be added before name of each property.
+ * Can be useful for separating properties with same name from different files.
+ */
+ @Parameter
+ private String keyPrefix = null;
+
+ public void setKeyPrefix( String keyPrefix )
+ {
+ this.keyPrefix = keyPrefix;
+ }
+
/**
* Used for resolving property placeholders.
*/
@@ -139,18 +150,18 @@ public class ReadPropertiesMojo
private void loadFiles()
throws MojoExecutionException
{
- for ( int i = 0; i < files.length; i++ )
+ for ( File file : files )
{
- load( new FileResource( files[i] ) );
+ load( new FileResource( file ) );
}
}
private void loadUrls()
throws MojoExecutionException
{
- for ( int i = 0; i < urls.length; i++ )
+ for ( String url : urls )
{
- load( new UrlResource( urls[i] ) );
+ load( new UrlResource( url ) );
}
}
@@ -174,15 +185,22 @@ public class ReadPropertiesMojo
{
getLog().debug( "Loading properties from " + resource );
- final InputStream stream = resource.getInputStream();
-
- try
- {
- project.getProperties().load( stream );
- }
- finally
+ try ( InputStream stream = resource.getInputStream() )
{
- stream.close();
+ if ( keyPrefix != null )
+ {
+ Properties properties = new Properties();
+ properties.load( stream );
+ Properties projectProperties = project.getProperties();
+ for ( String key : properties.stringPropertyNames() )
+ {
+ projectProperties.put( keyPrefix + key, properties.get( key ) );
+ }
+ }
+ else
+ {
+ project.getProperties().load( stream );
+ }
}
}
catch ( IOException e )
@@ -227,7 +245,7 @@ public class ReadPropertiesMojo
{
String k = (String) n.nextElement();
String p = (String) projectProperties.get( k );
- if ( p.indexOf( "${env." ) != -1 )
+ if ( p.contains( "${env." ) )
{
useEnvVariables = true;
break;
@@ -358,10 +376,10 @@ public class ReadPropertiesMojo
{
if ( url.startsWith( CLASSPATH_PREFIX ) )
{
- String resource = url.substring( CLASSPATH_PREFIX.length(), url.length() );
+ String resource = url.substring( CLASSPATH_PREFIX.length() );
if ( resource.startsWith( SLASH_PREFIX ) )
{
- resource = resource.substring( 1, resource.length() );
+ resource = resource.substring( 1 );
}
this.url = getClass().getClassLoader().getResource( resource );
if ( this.url == null )
=====================================
src/main/java/org/codehaus/mojo/properties/SetSystemPropertiesMojo.java
=====================================
@@ -33,7 +33,6 @@ import org.apache.maven.plugins.annotations.Parameter;
* Sets system properties.
*
* @author <a href="mailto:markh at apache.org">Mark Hobson</a>
- * @version $Id$
*/
@Mojo( name = "set-system-properties", defaultPhase = LifecyclePhase.INITIALIZE, threadSafe = true )
public class SetSystemPropertiesMojo
@@ -53,7 +52,6 @@ public class SetSystemPropertiesMojo
* {@inheritDoc}
*/
public void execute()
- throws MojoExecutionException, MojoFailureException
{
if ( properties.isEmpty() )
{
=====================================
src/main/java/org/codehaus/mojo/properties/WriteActiveProfileProperties.java
=====================================
@@ -21,8 +21,9 @@ package org.codehaus.mojo.properties;
import org.apache.maven.model.Profile;
import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
-import java.util.Iterator;
import java.util.List;
import java.util.Properties;
@@ -30,9 +31,8 @@ import java.util.Properties;
* Writes properties of all active profiles to a file.
*
* @author <a href="mailto:zarars at gmail.com">Zarar Siddiqi</a>
- * @version $Id$
- * @goal write-active-profile-properties
*/
+ at Mojo( name = "write-active-profile-properties", defaultPhase = LifecyclePhase.NONE, threadSafe = true )
public class WriteActiveProfileProperties
extends AbstractWritePropertiesMojo
{
@@ -41,15 +41,14 @@ public class WriteActiveProfileProperties
throws MojoExecutionException
{
validateOutputFile();
- List<?> list = getProject().getActiveProfiles();
+ List<Profile> list = getProject().getActiveProfiles();
if ( getLog().isInfoEnabled() )
{
getLog().debug( list.size() + " profile(s) active" );
}
Properties properties = new Properties();
- for ( Iterator<?> iter = list.iterator(); iter.hasNext(); )
+ for ( Profile profile : list )
{
- Profile profile = (Profile) iter.next();
if ( profile.getProperties() != null )
{
properties.putAll( profile.getProperties() );
=====================================
src/main/java/org/codehaus/mojo/properties/WriteProjectProperties.java
=====================================
@@ -43,7 +43,6 @@ import java.util.Enumeration;
import java.util.Properties;
import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
@@ -51,7 +50,6 @@ import org.apache.maven.plugins.annotations.Mojo;
* Writes project properties to a file.
*
* @author <a href="mailto:zarars at gmail.com">Zarar Siddiqi</a>
- * @version $Id$
*/
@Mojo( name = "write-project-properties", defaultPhase = LifecyclePhase.NONE, threadSafe = true )
public class WriteProjectProperties
@@ -59,7 +57,7 @@ public class WriteProjectProperties
{
/** {@inheritDoc} */
public void execute()
- throws MojoExecutionException, MojoFailureException
+ throws MojoExecutionException
{
validateOutputFile();
Properties projProperties = new Properties();
=====================================
src/site/apt/usage.apt.vm
=====================================
@@ -60,7 +60,7 @@ Usage
<configuration>
<urls>
<url>classpath:/config/dev.properties</url>
- <url>file:///${env.HOME}/mydev.properties</file>
+ <url>file:///${env.HOME}/mydev.properties</url>
</urls>
</configuration>
</execution>
=====================================
src/test/java/org/codehaus/mojo/properties/PropertyResolverTest.java
=====================================
@@ -19,21 +19,22 @@ package org.codehaus.mojo.properties;
* under the License.
*/
-import junit.framework.TestCase;
+import static org.hamcrest.CoreMatchers.*;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.*;
+import org.junit.Test;
import org.apache.maven.plugin.MojoFailureException;
import java.util.Properties;
-import org.junit.matchers.JUnitMatchers;
/**
* Tests the support class that produces concrete values from a set of properties.
*/
public class PropertyResolverTest
- extends TestCase
{
private final PropertyResolver resolver = new PropertyResolver();
- public void testValidPlaceholderResolved()
- throws MojoFailureException
+ @Test
+ public void validPlaceholderIsResolved()
{
Properties properties = new Properties();
properties.setProperty( "p1", "${p2}" );
@@ -46,8 +47,8 @@ public class PropertyResolverTest
assertEquals( "value", value2 );
}
- public void testUnknownPlaceholderLeftAsIs()
- throws MojoFailureException
+ @Test
+ public void unknownPlaceholderIsLeftAsIs()
{
Properties properties = new Properties();
properties.setProperty( "p1", "${p2}" );
@@ -63,8 +64,8 @@ public class PropertyResolverTest
assertEquals( "${unknown}", value3 );
}
- public void testMultipleValuesResolved()
- throws MojoFailureException
+ @Test
+ public void multipleValuesAreResolved()
{
Properties properties = new Properties();
properties.setProperty( "hostname", "localhost" );
@@ -76,8 +77,8 @@ public class PropertyResolverTest
assertEquals( "http://localhost:8080/", value );
}
- public void testMalformedPlaceholderLeftAsIs()
- throws MojoFailureException
+ @Test
+ public void malformedPlaceholderIsLeftAsIs()
{
Properties properties = new Properties();
properties.setProperty( "p1", "${p2}" );
@@ -93,8 +94,8 @@ public class PropertyResolverTest
assertEquals( "${malformed", value4 );
}
- public void testPropertyDefinedAsItselfIllegal()
- throws MojoFailureException
+ @Test
+ public void propertyDefinedAsItselfIsIllegal()
{
Properties properties = new Properties();
properties.setProperty( "p1", "${p2}" );
@@ -113,7 +114,7 @@ public class PropertyResolverTest
}
catch ( IllegalArgumentException e )
{
- assertTrue( JUnitMatchers.containsString( "p5" ).matches( e.getMessage() ) );
+ assertThat( e.getMessage(), containsString( "p5" ) );
}
String value6 = null;
try
@@ -123,7 +124,7 @@ public class PropertyResolverTest
}
catch ( IllegalArgumentException e )
{
- assertTrue( JUnitMatchers.containsString( "p7" ).matches( e.getMessage() ) );
+ assertThat( e.getMessage(), containsString( "p7" ) );
}
assertEquals( "value", value1 );
@@ -132,8 +133,8 @@ public class PropertyResolverTest
assertNull( value6 );
}
- public void testValueObtainedFromSystemProperty()
- throws MojoFailureException
+ @Test
+ public void valueIsObtainedFromSystemProperty()
{
Properties saved = System.getProperties();
System.setProperty( "system.property", "system.value" );
@@ -153,8 +154,8 @@ public class PropertyResolverTest
}
}
- public void testValueObtainedFromEnvironmentProperty()
- throws MojoFailureException
+ @Test
+ public void valueIsObtainedFromEnvironmentProperty()
{
Properties environment = new Properties();
environment.setProperty( "PROPERTY", "env.value" );
@@ -167,7 +168,8 @@ public class PropertyResolverTest
assertEquals( "env.value", value );
}
- public void testResolverToleratesMissingProperty()
+ @Test
+ public void missingPropertyIsTolerated()
{
assertEquals( "", resolver.getPropertyValue( "non-existent", new Properties(), null ) );
}
=====================================
src/test/java/org/codehaus/mojo/properties/ReadPropertiesMojoTest.java
=====================================
@@ -0,0 +1,109 @@
+package org.codehaus.mojo.properties;
+
+import org.apache.maven.project.MavenProject;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.Properties;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class ReadPropertiesMojoTest {
+ private static final String NEW_LINE = System.getProperty("line.separator");
+
+ private MavenProject projectStub;
+ private ReadPropertiesMojo readPropertiesMojo;
+
+ @Before
+ public void setUp() {
+ projectStub = new MavenProject();
+ readPropertiesMojo = new ReadPropertiesMojo();
+ readPropertiesMojo.setProject(projectStub);
+ }
+
+
+ @Test
+ public void readPropertiesWithoutKeyprefix() throws Exception {
+ File testPropertyFile = getPropertyFileForTesting();
+ // load properties directly for comparison later
+ Properties testProperties = new Properties();
+ testProperties.load(new FileReader(testPropertyFile));
+
+ // do the work
+ readPropertiesMojo.setFiles(new File[]{testPropertyFile});
+ readPropertiesMojo.execute();
+
+ // check results
+ Properties projectProperties = projectStub.getProperties();
+ assertNotNull(projectProperties);
+ // it should not be empty
+ assertNotEquals(0, projectProperties.size());
+
+ // we are not adding prefix, so properties should be same as in file
+ assertEquals(testProperties.size(), projectProperties.size());
+ assertEquals(testProperties, projectProperties);
+
+ }
+
+ @Test
+ public void readPropertiesWithKeyprefix() throws Exception {
+ String keyPrefix = "testkey-prefix.";
+
+ File testPropertyFileWithoutPrefix = getPropertyFileForTesting();
+ Properties testPropertiesWithoutPrefix = new Properties();
+ testPropertiesWithoutPrefix.load(new FileReader(testPropertyFileWithoutPrefix));
+ // do the work
+ readPropertiesMojo.setKeyPrefix(keyPrefix);
+ readPropertiesMojo.setFiles(new File[]{testPropertyFileWithoutPrefix});
+ readPropertiesMojo.execute();
+
+ // load properties directly and add prefix for comparison later
+ Properties testPropertiesPrefix = new Properties();
+ testPropertiesPrefix.load(new FileReader(getPropertyFileForTesting(keyPrefix)));
+
+ // check results
+ Properties projectProperties = projectStub.getProperties();
+ assertNotNull(projectProperties);
+ // it should not be empty
+ assertNotEquals(0, projectProperties.size());
+
+ // we are adding prefix, so prefix properties should be same as in projectProperties
+ assertEquals(testPropertiesPrefix.size(), projectProperties.size());
+ assertEquals(testPropertiesPrefix, projectProperties);
+
+ // properties with and without prefix shouldn't be same
+ assertNotEquals(testPropertiesPrefix, testPropertiesWithoutPrefix);
+ assertNotEquals(testPropertiesWithoutPrefix, projectProperties);
+
+ }
+
+ private File getPropertyFileForTesting() throws IOException {
+ return getPropertyFileForTesting(null);
+ }
+
+ private File getPropertyFileForTesting(String keyPrefix) throws IOException {
+ File f = File.createTempFile("prop-test", ".properties");
+ f.deleteOnExit();
+ FileWriter writer = new FileWriter(f);
+ String prefix = keyPrefix;
+ if (prefix == null) {
+ prefix = "";
+ }
+ try {
+ writer.write(prefix + "test.property1=value1" + NEW_LINE);
+ writer.write(prefix + "test.property2=value2" + NEW_LINE);
+ writer.write(prefix + "test.property3=value3" + NEW_LINE);
+ writer.flush();
+ } finally {
+ writer.close();
+ }
+ return f;
+ }
+
+}
View it on GitLab: https://salsa.debian.org/java-team/properties-maven-plugin/-/compare/93a456602de917f9c59fc0509cf2e2b551593c3a...3772eb6434ecee61a5e426fe917059b2248a65ff
--
View it on GitLab: https://salsa.debian.org/java-team/properties-maven-plugin/-/compare/93a456602de917f9c59fc0509cf2e2b551593c3a...3772eb6434ecee61a5e426fe917059b2248a65ff
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20221206/5ff6d624/attachment.htm>
More information about the pkg-java-commits
mailing list