-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8a3fe1
commit dc27a53
Showing
8 changed files
with
517 additions
and
239 deletions.
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 |
---|---|---|
|
@@ -5,5 +5,6 @@ nbproject/build-impl.xml | |
nbproject/genfiles.properties | ||
nbproject/private/* | ||
.gradle | ||
.m2-cache | ||
|
||
build-ext.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
This file was deleted.
Oops, something went wrong.
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
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
154 changes: 154 additions & 0 deletions
154
src/com/liferay/netbeansproject/container/Coordinate.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,154 @@ | ||
/** | ||
* SPDX-FileCopyrightText: (c) 2023 Liferay, Inc. https://liferay.com | ||
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06 | ||
*/ | ||
|
||
package com.liferay.netbeansproject.container; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Objects; | ||
|
||
/** | ||
* @author Shuyang Zhou | ||
*/ | ||
public class Coordinate implements Comparable<Coordinate> { | ||
|
||
public Coordinate(String line) { | ||
String[] parts = line.split(":"); | ||
|
||
_groupId = parts[0]; | ||
_artifactId = parts[1]; | ||
_version = parts[2]; | ||
_test = false; | ||
|
||
_filePath = _toFilePath(_groupId, _artifactId, _version); | ||
} | ||
|
||
|
||
public Coordinate( | ||
String groupId, String artifactId, String version, boolean test) { | ||
|
||
_groupId = groupId; | ||
_artifactId = artifactId; | ||
_version = version; | ||
_test = test; | ||
|
||
_filePath = _toFilePath(groupId, artifactId, version); | ||
} | ||
|
||
public Dependency toDependency(Path basePath) { | ||
Path sourcePath = basePath.resolve(_filePath.replace(".jar", "-sources.jar")); | ||
|
||
if (Files.notExists(sourcePath)) { | ||
sourcePath = null; | ||
} | ||
else { | ||
sourcePath = sourcePath.toAbsolutePath(); | ||
} | ||
|
||
return new Dependency(basePath.resolve(_filePath).toAbsolutePath(), sourcePath, _test); | ||
} | ||
|
||
private static String _toFilePath(String groupId, String artifactId, String version) { | ||
StringBuilder sb = new StringBuilder(); | ||
|
||
sb.append(groupId.replace('.', '/')); | ||
sb.append('/'); | ||
sb.append(artifactId); | ||
sb.append('/'); | ||
sb.append(version); | ||
sb.append('/'); | ||
sb.append(artifactId); | ||
sb.append('-'); | ||
sb.append(version); | ||
sb.append(".jar"); | ||
|
||
return sb.toString(); | ||
} | ||
public String getFilePath() { | ||
return _filePath; | ||
} | ||
|
||
public String getGroupId() { | ||
return _groupId; | ||
} | ||
|
||
public String getArtifactId() { | ||
return _artifactId; | ||
} | ||
|
||
public String getVersion() { | ||
return _version; | ||
} | ||
|
||
public boolean isTest() { | ||
return _test; | ||
} | ||
|
||
public void setTest(boolean test) { | ||
_test = test; | ||
} | ||
|
||
private final String _groupId; | ||
private final String _artifactId; | ||
private final String _version; | ||
private boolean _test; | ||
private final String _filePath; | ||
|
||
@Override | ||
public int hashCode() { | ||
int hash = 7; | ||
hash = 67 * hash + Objects.hashCode(this._groupId); | ||
hash = 67 * hash + Objects.hashCode(this._artifactId); | ||
hash = 67 * hash + Objects.hashCode(this._version); | ||
hash = 67 * hash + (this._test ? 1 : 0); | ||
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 Coordinate other = (Coordinate)obj; | ||
if (!Objects.equals(this._groupId, other._groupId)) { | ||
return false; | ||
} | ||
if (!Objects.equals(this._artifactId, other._artifactId)) { | ||
return false; | ||
} | ||
return Objects.equals(this._version, other._version); | ||
} | ||
|
||
|
||
@Override | ||
public int compareTo(Coordinate coordinate) { | ||
int result = _groupId.compareTo(coordinate._groupId); | ||
|
||
if (result != 0) { | ||
return result; | ||
} | ||
|
||
result = _artifactId.compareTo(coordinate._artifactId); | ||
|
||
if (result != 0) { | ||
return result; | ||
} | ||
|
||
return _version.compareTo(coordinate._version); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return _groupId + ":" + _artifactId + ":" + _version; | ||
} | ||
|
||
} |
Oops, something went wrong.