Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding sort option for build-classpath #188

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/it/projects/build-classpath-sorted/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 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.

invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:build-classpath
68 changes: 68 additions & 0 deletions src/it/projects/build-classpath-sorted/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?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.
-->

<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.apache.maven.its.dependency</groupId>
<artifactId>build-classpath-sorted</artifactId>
<version>1.0-SNAPSHOT</version>

<name>Test</name>
<description>
Test dependency:build-classpath -Dmdep.sortClasspath=true
</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-profile</artifactId>
<version>2.0.6</version>
<exclusions>
<exclusion>
<!-- NOTE: Excluded because of questionable handling of dependencyManagement in maven-profile:pom:2.0.6 -->
<groupId>classworlds</groupId>
<artifactId>classworlds</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- one dependency with classifier -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.0.6</version>
<classifier>sources</classifier>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

</project>
22 changes: 22 additions & 0 deletions src/it/projects/build-classpath-sorted/test.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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.

mdep.outputFile = target/classpath.txt
mdep.fileSeparator = /
mdep.pathSeparator = :
mdep.prefix = PREFIX
mdep.sortClasspath = true
33 changes: 33 additions & 0 deletions src/it/projects/build-classpath-sorted/verify.bsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import java.io.File;

import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.StringUtils;

String classpath = StringUtils.replace( FileUtils.fileRead( new File( basedir, "target/classpath.txt" ) ), "PREFIX/", "" );
String expected = "junit-3.8.1.jar:maven-model-2.0.6.jar:maven-profile-2.0.6.jar:maven-project-2.0.6-sources.jar:plexus-container-default-1.0-alpha-9-stable-1.jar:plexus-utils-1.4.1.jar";

if ( !classpath.equals( expected ) )
{
throw new Exception( "Unexpected classpath: '" + classpath + "'" );
}

return true;
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ public class BuildClasspathMojo
@Parameter( property = "outputEncoding", defaultValue = "${project.reporting.outputEncoding}" )
private String outputEncoding;

/**
* Should the classpath be lexicographically sorted.
*/
@Parameter( property = "mdep.sortClasspath", defaultValue = "false" )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@since tag is missing

private boolean sortClasspath = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

false is default value, initialization is redundant


/**
* Strip artifact version during copy (only works if prefix is set)
*/
Expand Down Expand Up @@ -197,6 +203,10 @@ protected void doExecute()
}

List<Artifact> artList = new ArrayList<>( artifacts );
if ( sortClasspath )
{
artList.sort( this );
}

StringBuilder sb = new StringBuilder();
Iterator<Artifact> i = artList.iterator();
Expand Down