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
Initial implementation of Project Dependency API #4149
Merged
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a516850
Initial implementation of Project Dependency API
sdedic 7784f1e
Revert unwanted changes from local experiments.
sdedic e21bd89
Fixed CRLF line ends.
sdedic 284bdd6
Fixing module properties, should be invisible+autoload.
sdedic 6860fa9
Licenses added.
sdedic 0221749
Removing LATEST version, not needed now.
sdedic f3ee411
Review: removed unwanted changes to vscode extension.
sdedic 18e354e
License added.
sdedic 9741151
Made compilable with JDK8
sdedic 4d8cad4
Fixing test: do a priming build in order to download ext. dependencie…
sdedic File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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,14 @@ | ||
# Project Dependencies | ||
|
||
This module is highly experimental; provides an abstract API to query project dependncies | ||
that shall be implemented by | ||
- gradle | ||
- maven | ||
- ant/nbm support | ||
At this moment, just Maven implements it and I need to validate the API design by adding | ||
the other implementations before the API is going to be published officially. In the | ||
meantime, implementation dependencies are required to access / implement the API. | ||
|
||
The code will **eventually merge** into `project.api` module and this experimental one | ||
will be deleted. | ||
|
This file contains 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,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project basedir="." default="netbeans" name="ide/project.dependency"> | ||
<description>Builds, tests, and runs the project org.netbeans.modules.project.dependency</description> | ||
<import file="../../nbbuild/templates/projectized.xml"/> | ||
</project> |
This file contains 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,5 @@ | ||
Manifest-Version: 1.0 | ||
AutoUpdate-Show-In-Client: false | ||
OpenIDE-Module: org.netbeans.modules.project.dependency | ||
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/project/dependency/Bundle.properties | ||
OpenIDE-Module-Implementation-Version: 1 |
This file contains 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,4 @@ | ||
is.autoload=true | ||
javac.source=1.8 | ||
javac.compilerargs=-Xlint -Xlint:-serial | ||
spec.version.base=1.0.0 |
This file contains 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,46 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://www.netbeans.org/ns/project/1"> | ||
<type>org.netbeans.modules.apisupport.project</type> | ||
<configuration> | ||
<data xmlns="http://www.netbeans.org/ns/nb-module-project/3"> | ||
<code-name-base>org.netbeans.modules.project.dependency</code-name-base> | ||
<module-dependencies> | ||
<dependency> | ||
<code-name-base>org.netbeans.api.annotations.common</code-name-base> | ||
<build-prerequisite/> | ||
<compile-dependency/> | ||
<run-dependency> | ||
<release-version>1</release-version> | ||
<specification-version>1.45</specification-version> | ||
</run-dependency> | ||
</dependency> | ||
<dependency> | ||
<code-name-base>org.netbeans.modules.projectapi</code-name-base> | ||
<build-prerequisite/> | ||
<compile-dependency/> | ||
<run-dependency> | ||
<release-version>1</release-version> | ||
<specification-version>1.87</specification-version> | ||
</run-dependency> | ||
</dependency> | ||
<dependency> | ||
<code-name-base>org.openide.filesystems</code-name-base> | ||
<build-prerequisite/> | ||
<compile-dependency/> | ||
<run-dependency> | ||
<specification-version>9.29</specification-version> | ||
</run-dependency> | ||
</dependency> | ||
<dependency> | ||
<code-name-base>org.openide.util.lookup</code-name-base> | ||
<build-prerequisite/> | ||
<compile-dependency/> | ||
<run-dependency> | ||
<specification-version>8.51</specification-version> | ||
</run-dependency> | ||
</dependency> | ||
</module-dependencies> | ||
<public-packages/> | ||
</data> | ||
</configuration> | ||
</project> |
193 changes: 193 additions & 0 deletions
193
ide/project.dependency/src/org/netbeans/modules/project/dependency/ArtifactSpec.java
This file contains 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,193 @@ | ||
/* | ||
* 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. | ||
*/ | ||
package org.netbeans.modules.project.dependency; | ||
|
||
import java.util.Objects; | ||
import org.netbeans.api.annotations.common.NonNull; | ||
import org.netbeans.api.annotations.common.NullAllowed; | ||
|
||
/** | ||
* Represents an artifact. Each artifact is identified by | ||
* <ul> | ||
* <li>group or organization id | ||
* <li>artifact id | ||
* <li>version | ||
* <li>(optional) classifier; no classifier shall be interpreted as a | ||
* regular build artifact | ||
* <li>(optional) type; not type shall be interepreted as the default type | ||
* for the processing compiler or builder | ||
* </ul> | ||
* The version specified is further classified by {@link VersionKind}, to | ||
* distinguish versions possibly from repositories, development versions and | ||
* floating versions. | ||
* | ||
* @author sdedic | ||
*/ | ||
public final class ArtifactSpec<T> { | ||
/** | ||
* Kind of the artifact version | ||
*/ | ||
public enum VersionKind { | ||
/** | ||
* Regular publishable artifact | ||
*/ | ||
REGULAR, | ||
|
||
/** | ||
* Snapshot artifact | ||
*/ | ||
SNAPSHOT, | ||
|
||
/** | ||
* Regular artifact, floating version | ||
*/ | ||
LATEST | ||
}; | ||
|
||
private final VersionKind kind; | ||
private final String type; | ||
private final String groupId; | ||
private final String artifactId; | ||
private final String versionSpec; | ||
private final String classifier; | ||
private final boolean optional; | ||
final T data; | ||
|
||
ArtifactSpec(VersionKind kind, String groupId, String artifactId, String versionSpec, String type, String classifier, boolean optional, T impl) { | ||
this.kind = kind; | ||
this.groupId = groupId; | ||
this.artifactId = artifactId; | ||
this.versionSpec = versionSpec; | ||
this.classifier = classifier; | ||
this.optional = optional; | ||
this.data = impl; | ||
this.type = type; | ||
} | ||
|
||
public VersionKind getKind() { | ||
return kind; | ||
} | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
public String getGroupId() { | ||
return groupId; | ||
} | ||
|
||
public String getArtifactId() { | ||
return artifactId; | ||
} | ||
|
||
public String getVersionSpec() { | ||
return versionSpec; | ||
} | ||
|
||
public String getClassifier() { | ||
return classifier; | ||
} | ||
|
||
public boolean isOptional() { | ||
return optional; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int hash = 7; | ||
hash = 79 * hash + Objects.hashCode(this.kind); | ||
hash = 79 * hash + Objects.hashCode(this.type); | ||
hash = 79 * hash + Objects.hashCode(this.groupId); | ||
hash = 79 * hash + Objects.hashCode(this.artifactId); | ||
hash = 79 * hash + Objects.hashCode(this.versionSpec); | ||
hash = 79 * hash + Objects.hashCode(this.classifier); | ||
return hash; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
if (obj == null) { | ||
return false; | ||
} | ||
if (getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
final ArtifactSpec<?> other = (ArtifactSpec<?>) obj; | ||
if (!Objects.equals(this.type, other.type)) { | ||
return false; | ||
} | ||
if (!Objects.equals(this.groupId, other.groupId)) { | ||
return false; | ||
} | ||
if (!Objects.equals(this.artifactId, other.artifactId)) { | ||
return false; | ||
} | ||
if (!Objects.equals(this.versionSpec, other.versionSpec)) { | ||
return false; | ||
} | ||
if (!Objects.equals(this.classifier, other.classifier)) { | ||
return false; | ||
} | ||
return this.kind == other.kind; | ||
} | ||
|
||
public String toString() { | ||
StringBuilder sb = new StringBuilder( | ||
String.format("%s:%s:%s", getGroupId(), getArtifactId(), getVersionSpec() == null ? "" : getVersionSpec()) | ||
); | ||
if (classifier != null) { | ||
sb.append(":").append(classifier); | ||
} | ||
if (type != null) { | ||
sb.append("[").append(type).append("]"); | ||
} | ||
if (optional) { | ||
sb.append("?"); | ||
} | ||
return sb.toString(); | ||
} | ||
|
||
/** | ||
* Returns opaque project-specific data. If searching for | ||
* a project-specific extension, use {@link ProjectDependencies#findAdapters} instead. | ||
* | ||
* @return unspecified underlying project data | ||
*/ | ||
public T getProjectData() { | ||
return data; | ||
} | ||
|
||
public static <V> ArtifactSpec<V> createVersionSpec( | ||
@NonNull String groupId, @NonNull String artifactId, | ||
@NullAllowed String type, @NullAllowed String classifier, | ||
@NonNull String versionSpec, boolean optional, @NonNull V data) { | ||
return new ArtifactSpec<V>(VersionKind.REGULAR, groupId, artifactId, versionSpec, type, classifier, optional, data); | ||
} | ||
|
||
public static <V> ArtifactSpec<V> createSnapshotSpec( | ||
@NonNull String groupId, @NonNull String artifactId, | ||
@NullAllowed String type, @NullAllowed String classifier, | ||
@NonNull String versionSpec, boolean optional, @NonNull V data) { | ||
return new ArtifactSpec<V>(VersionKind.SNAPSHOT, groupId, artifactId, versionSpec, type, classifier, false, data); | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
ide/project.dependency/src/org/netbeans/modules/project/dependency/Bundle.properties
This file contains 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 @@ | ||
OpenIDE-Module-Name=Project Dependencies |
84 changes: 84 additions & 0 deletions
84
ide/project.dependency/src/org/netbeans/modules/project/dependency/Dependency.java
This file contains 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,84 @@ | ||
/* | ||
* 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. | ||
*/ | ||
package org.netbeans.modules.project.dependency; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Represents a dependency of an artifact. The {@link #getChildren()} artifacts are | ||
* needed in a certain {@link #getScope()}; should be ignored in unrelated scopes. | ||
* The artifact that is subject of this dependency is the {@link #getArtifact()}. | ||
* Children are expressed using other {@link Dependency} instances. | ||
* <p> | ||
* Dependency does not have well-defined {@link #equals} and {@link #hashCode}, use | ||
* {@link #getArtifact()} as key in Maps. | ||
* | ||
* @author sdedic | ||
*/ | ||
public final class Dependency { | ||
private final ArtifactSpec artifact; | ||
private final List<Dependency> children; | ||
private final Scope scope; | ||
final Object data; | ||
|
||
Dependency(ArtifactSpec artifact, List<Dependency> children, Scope scope, Object data) { | ||
this.artifact = artifact; | ||
this.children = children; | ||
this.scope = scope; | ||
this.data = data; | ||
} | ||
|
||
public ArtifactSpec getArtifact() { | ||
return artifact; | ||
} | ||
|
||
public List<Dependency> getChildren() { | ||
return children; | ||
} | ||
|
||
public Scope getScope() { | ||
return scope; | ||
} | ||
|
||
public Object getProjectData() { | ||
return data; | ||
} | ||
|
||
public String toString() { | ||
return getArtifact() + "[" + scope + "]"; | ||
} | ||
|
||
public static Dependency create(ArtifactSpec artifact, Scope scope, List<Dependency> children, Object data) { | ||
return new Dependency(artifact, children, scope, data); | ||
} | ||
|
||
/** | ||
* Allows to filter artifacts and their dependency subtrees. | ||
*/ | ||
public interface Filter { | ||
/** | ||
* Decide if the artifact 'a' and its dependencies should be included in the report. | ||
* @param s the scope which requires dependency on "a" | ||
* @param a the artifact | ||
* @return true, if "a" should be included in the result; false to exclude it and its | ||
* dependencies. | ||
*/ | ||
public boolean accept(Scope s, ArtifactSpec a); | ||
} | ||
} |
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.
And VersionKind.Latest? We don't need it now?
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.
will remove. Can be added 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.
Removed in 0221749