-
Notifications
You must be signed in to change notification settings - Fork 51
[MSHARED-632] Expose which dependency classes are used and where #20
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
src/main/java/org/apache/maven/shared/dependency/analyzer/DependencyUsage.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| package org.apache.maven.shared.dependency.analyzer; | ||
|
|
||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| /** | ||
| * Usage of a dependency class by a project class. | ||
| * | ||
| * @author <a href="mailto:[email protected]">Jonathan Haber</a> | ||
| */ | ||
| public class DependencyUsage | ||
jhaber marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| // fields ----------------------------------------------------------------- | ||
|
|
||
| private final String dependencyClass; | ||
|
|
||
| private final String usedBy; | ||
|
|
||
| // constructors ----------------------------------------------------------- | ||
|
|
||
| public DependencyUsage( String dependencyClass, String usedBy ) | ||
jhaber marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| this.dependencyClass = dependencyClass; | ||
| this.usedBy = usedBy; | ||
| } | ||
|
|
||
| // public methods --------------------------------------------------------- | ||
|
|
||
|
|
||
| public String getDependencyClass() | ||
| { | ||
| return dependencyClass; | ||
| } | ||
|
|
||
| public String getUsedBy() | ||
| { | ||
| return usedBy; | ||
| } | ||
|
|
||
| // Object methods --------------------------------------------------------- | ||
|
|
||
| /* | ||
| * @see java.lang.Object#hashCode() | ||
| */ | ||
| public int hashCode() | ||
| { | ||
| int hashCode = dependencyClass.hashCode(); | ||
| hashCode = ( hashCode * 37 ) + usedBy.hashCode(); | ||
|
|
||
| return hashCode; | ||
| } | ||
|
|
||
| /* | ||
| * @see java.lang.Object#equals(java.lang.Object) | ||
| */ | ||
| public boolean equals( Object object ) | ||
| { | ||
| if ( object instanceof DependencyUsage ) | ||
| { | ||
| DependencyUsage usage = (DependencyUsage) object; | ||
|
|
||
| return getDependencyClass().equals( usage.getDependencyClass() ) | ||
| && getUsedBy().equals( usage.getUsedBy() ); | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| /* | ||
| * @see java.lang.Object#toString() | ||
| */ | ||
| public String toString() | ||
| { | ||
| StringBuilder buffer = new StringBuilder(); | ||
|
|
||
| buffer.append( "dependencyClass=" ).append( getDependencyClass() ); | ||
| buffer.append( "," ); | ||
| buffer.append( "usedBy=" ).append( getUsedBy() ); | ||
|
|
||
| buffer.insert( 0, "[" ); | ||
| buffer.insert( 0, getClass().getName() ); | ||
|
|
||
| buffer.append( "]" ); | ||
|
|
||
| return buffer.toString(); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an incompatible change. Would it make sense to simply make analyze include usages?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How were you thinking that would work, change the return type of
analyzemethod? Isn't that also incompatible? And just to confirm, you're thinking about the case where someone wrote a custom implementation ofDependencyAnalyzerand registered it for use with the dependency plugin?One option that comes to mind is making
analyzeWithUsagesa default interface method with an implementation that throws something likeUnsupportedOperationException. That way the dependency plugin can try to gracefully handle this case and fall back to the regularanalyzemethod, for example:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have default interface methods until java 8. :-(
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case another option is to keep things as-is and have the dependency plugin use the same pseudo-code as above, except it would catch something like
NoSuchMethodErrorinstead ofUnsupportedOperationException(with a comment explaining the situation). Certainly not ideal, but it seems like we ultimately need some way for the dependency plugin to detect that the analyzer doesn't support the new functionality and gracefully degrade