Skip to content
Merged
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
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 = clean package ${project.groupId}:${project.artifactId}:${project.version}:analyze-only -Dverbose
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?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.shared.dependency-analyzer.tests</groupId>
<artifactId>usedUndeclaredReference</artifactId>
<version>1.0</version>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package usedUndeclaredReference;

/*
* 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.
*/

public class Project
{
public static final Class CLASS_REF = org.apache.xmlcommons.Version.class;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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 org.codehaus.plexus.util.*;

String log = FileUtils.fileRead( new File( basedir, "build.log" ) );
Comment on lines +20 to +22
Copy link
Member

Choose a reason for hiding this comment

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

We can use groovy script here ... and we needn't external dependencies.
look for build.log reading in another groovy scripts


log = StringUtils.unifyLineSeparators(log, "\n");

String expected = "[WARNING] Used undeclared dependencies found:\n"
+ "[WARNING] xml-apis:xml-apis:jar:1.0.b2:compile\n"
+ "[WARNING] class org.apache.xmlcommons.Version\n";
Comment on lines +26 to +28
Copy link
Member

Choose a reason for hiding this comment

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

we must use system native end line ...


if ( !log.contains(expected) )
{
throw new Exception( "Expected warning missing" );
}

return true;
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -327,7 +329,8 @@ private boolean checkDependencies()
}

Set<Artifact> usedDeclared = new LinkedHashSet<>( analysis.getUsedDeclaredArtifacts() );
Set<Artifact> usedUndeclared = new LinkedHashSet<>( analysis.getUsedUndeclaredArtifacts() );
Map<Artifact, Set<String>> usedUndeclaredWithClasses =
new LinkedHashMap<>( analysis.getUsedUndeclaredArtifactsWithClasses() );
Set<Artifact> unusedDeclared = new LinkedHashSet<>( analysis.getUnusedDeclaredArtifacts() );
Set<Artifact> testArtifactsWithNonTestScope = new LinkedHashSet<>(
analysis.getTestArtifactsWithNonTestScope() );
Expand All @@ -340,8 +343,9 @@ private boolean checkDependencies()
filterArtifactsByScope( unusedDeclared, Artifact.SCOPE_RUNTIME );
}

ignoredUsedUndeclared.addAll( filterDependencies( usedUndeclared, ignoredDependencies ) );
ignoredUsedUndeclared.addAll( filterDependencies( usedUndeclared, ignoredUsedUndeclaredDependencies ) );
ignoredUsedUndeclared.addAll( filterDependencies( usedUndeclaredWithClasses.keySet(), ignoredDependencies ) );
ignoredUsedUndeclared.addAll( filterDependencies( usedUndeclaredWithClasses.keySet(),
ignoredUsedUndeclaredDependencies ) );

ignoredUnusedDeclared.addAll( filterDependencies( unusedDeclared, ignoredDependencies ) );
ignoredUnusedDeclared.addAll( filterDependencies( unusedDeclared, ignoredUnusedDeclaredDependencies ) );
Expand All @@ -357,11 +361,18 @@ private boolean checkDependencies()
reported = true;
}

if ( !usedUndeclared.isEmpty() )
if ( !usedUndeclaredWithClasses.isEmpty() )
{
getLog().warn( "Used undeclared dependencies found:" );

logArtifacts( usedUndeclared, true );
if ( verbose )
{
logArtifacts( usedUndeclaredWithClasses, true );
}
else
{
logArtifacts( usedUndeclaredWithClasses.keySet(), true );
}
reported = true;
warning = true;
}
Expand Down Expand Up @@ -402,12 +413,12 @@ private boolean checkDependencies()

if ( outputXML )
{
writeDependencyXML( usedUndeclared );
writeDependencyXML( usedUndeclaredWithClasses.keySet() );
}

if ( scriptableOutput )
{
writeScriptableOutput( usedUndeclared );
writeScriptableOutput( usedUndeclaredWithClasses.keySet() );
}

if ( !reported )
Expand Down Expand Up @@ -449,6 +460,40 @@ private void logArtifacts( Set<Artifact> artifacts, boolean warn )
}
}

private void logArtifacts( Map<Artifact, Set<String>> artifacts, boolean warn )
{
if ( artifacts.isEmpty() )
{
getLog().info( " None" );
}
else
{
for ( Map.Entry<Artifact, Set<String>> entry : artifacts.entrySet() )
{
// called because artifact will set the version to -SNAPSHOT only if I do this. MNG-2961
entry.getKey().isSnapshot();

if ( warn )
{
getLog().warn( " " + entry.getKey() );
for ( String clazz : entry.getValue() )
{
getLog().warn( " class " + clazz );
}
}
else
{
getLog().info( " " + entry.getKey() );
for ( String clazz : entry.getValue() )
{
getLog().info( " class " + clazz );
}
}

}
}
}

private void writeDependencyXML( Set<Artifact> artifacts )
{
if ( !artifacts.isEmpty() )
Expand Down