release version 1.10.0
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<version>1.9.0</version>
|
||||
<version>1.10.0</version>
|
||||
</parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.core</groupId>
|
||||
<artifactId>artifact-management</artifactId>
|
||||
@ -14,13 +14,13 @@
|
||||
<properties>
|
||||
<bundle.osgi.export.pkg>
|
||||
ru.entaxy.platform.core.artifact*,
|
||||
ru.entaxy.platform.core.artifact.*
|
||||
ru.entaxy.platform.core.artifact.*,
|
||||
ru.entaxy.platform.core.artifact.repository.impl
|
||||
</bundle.osgi.export.pkg>
|
||||
<bundle.osgi.private.pkg>
|
||||
ru.entaxy.platform.core.artifact.impl,
|
||||
ru.entaxy.platform.core.artifact.installer.builder.impl,
|
||||
ru.entaxy.platform.core.artifact.installer.impl,
|
||||
ru.entaxy.platform.core.artifact.repository.impl,
|
||||
ru.entaxy.platform.core.artifact.repository.impl.remote,
|
||||
ru.entaxy.platform.core.artifact.service.impl
|
||||
</bundle.osgi.private.pkg>
|
||||
@ -128,16 +128,10 @@
|
||||
<artifactId>commons-codec</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ru.entaxy.esb.system.commons</groupId>
|
||||
<artifactId>system-commons</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>xml-apis</groupId>
|
||||
<artifactId>xml-apis</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.core</groupId>
|
||||
<artifactId>core-support-runtime-legacy</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -36,277 +36,347 @@ import ru.entaxy.platform.base.support.CommonUtils;
|
||||
|
||||
public class ArtifactCoordinates {
|
||||
|
||||
public static final ArtifactCoordinates EMPTY = new ArtifactCoordinates();
|
||||
|
||||
public static final String DEFAULT_VERSION = "1.0.0";
|
||||
|
||||
public static final String SNAPSHOT_QUALIFIER = "SNAPSHOT";
|
||||
|
||||
// x.y.z[-qualifier]
|
||||
public static final String VERSION_POLICY_CLEAR = "";
|
||||
// x.y.z-timestamp
|
||||
public static final String VERSION_POLICY_TIMESTAMPED = "timestamped";
|
||||
// x.y.z-yyMMddHHmmss
|
||||
public static final String VERSION_POLICY_DATED = "dated";
|
||||
// x.yyMMdd.HHmmss[-qualifier]
|
||||
public static final String VERSION_POLICY_DATED_EMBEDDED = "dated-embedded";
|
||||
|
||||
protected String groupId;
|
||||
protected String artifactId;
|
||||
protected String version = "1.0";
|
||||
protected String type;
|
||||
protected String classifier;
|
||||
public static final ArtifactCoordinates EMPTY = new ArtifactCoordinates();
|
||||
|
||||
protected String versionPolicy = VERSION_POLICY_CLEAR;
|
||||
|
||||
protected String versionQualifier = "";
|
||||
|
||||
protected String timestamp = "";
|
||||
|
||||
protected Calendar calendar = null;
|
||||
|
||||
protected boolean isSnapshot = false;
|
||||
|
||||
protected Set<String> allowedPolicies = new HashSet<>() {/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
public static final String DEFAULT_VERSION = "1.0.0";
|
||||
|
||||
{
|
||||
add(VERSION_POLICY_CLEAR);
|
||||
add(VERSION_POLICY_DATED);
|
||||
add(VERSION_POLICY_DATED_EMBEDDED);
|
||||
add(VERSION_POLICY_TIMESTAMPED);
|
||||
}};
|
||||
|
||||
public ArtifactCoordinates groupId(String groupId) {
|
||||
setGroupId(groupId);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArtifactCoordinates artifactId(String artifactId) {
|
||||
setArtifactId(artifactId);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArtifactCoordinates versionPolicy(String versionPolicy) {
|
||||
if (this.allowedPolicies.contains(versionPolicy))
|
||||
this.versionPolicy = versionPolicy;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArtifactCoordinates version(String version) {
|
||||
this.versionQualifier = "";
|
||||
setVersion(version);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArtifactCoordinates timestampedVersion(String version) {
|
||||
this.version(version);
|
||||
this.timestamped();
|
||||
// versionQualifier = "-" + Calendar.getInstance().getTimeInMillis();
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArtifactCoordinates timestamp(String timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArtifactCoordinates timestamped() {
|
||||
return timestamped(Calendar.getInstance().getTimeInMillis()+"");
|
||||
}
|
||||
|
||||
public ArtifactCoordinates timestamped(String timestamp) {
|
||||
if (CommonUtils.isValid(timestamp)) {
|
||||
this.timestamp = timestamp;
|
||||
this.versionPolicy(VERSION_POLICY_TIMESTAMPED);
|
||||
} else {
|
||||
this.timestamp = "";
|
||||
this.versionPolicy(VERSION_POLICY_CLEAR);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public static final String DEFAULT_TYPE = "jar";
|
||||
|
||||
public ArtifactCoordinates datedVersion(String version) {
|
||||
this.version(version);
|
||||
this.dated();
|
||||
// versionQualifier = "-" + Calendar.getInstance().getTimeInMillis();
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArtifactCoordinates dated() {
|
||||
this.calendar = Calendar.getInstance();
|
||||
versionPolicy(VERSION_POLICY_DATED);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArtifactCoordinates datedEmbeddedVersion(String version) {
|
||||
this.version(version);
|
||||
this.datedEmbedded();
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArtifactCoordinates datedEmbedded() {
|
||||
this.calendar = Calendar.getInstance();
|
||||
versionPolicy(VERSION_POLICY_DATED_EMBEDDED);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected String getResultQualifier() {
|
||||
if (isSnapshot)
|
||||
return "-" + SNAPSHOT_QUALIFIER;
|
||||
if (CommonUtils.isValid(this.versionQualifier))
|
||||
return "-" + this.versionQualifier;
|
||||
return "";
|
||||
}
|
||||
|
||||
protected String calculateFinalVersion() {
|
||||
if (VERSION_POLICY_TIMESTAMPED.equals(this.versionPolicy)) {
|
||||
if (!CommonUtils.isValid(this.timestamp))
|
||||
this.timestamp = Calendar.getInstance().getTimeInMillis() + "";
|
||||
return this.version + "-" + this.timestamp;
|
||||
}
|
||||
if (VERSION_POLICY_DATED.equals(this.versionPolicy)) {
|
||||
prepareCalendar();
|
||||
return this.version + "-" + ((new SimpleDateFormat("yyMMddHHmmss")).format(this.calendar.getTime()));
|
||||
}
|
||||
if (VERSION_POLICY_DATED_EMBEDDED.equals(this.versionPolicy)) {
|
||||
prepareCalendar();
|
||||
return this.version.split("\\.")[0]
|
||||
+ "."
|
||||
+ ((new SimpleDateFormat("yyMMdd.HHmmss")).format(this.calendar.getTime()))
|
||||
+ getResultQualifier();
|
||||
}
|
||||
return this.version + this.getResultQualifier();
|
||||
}
|
||||
|
||||
protected void prepareCalendar() {
|
||||
if (this.calendar == null)
|
||||
this.calendar = Calendar.getInstance();
|
||||
if (CommonUtils.isValid(this.timestamp)) {
|
||||
try {
|
||||
this.calendar.setTimeInMillis(Long.parseLong(this.timestamp));
|
||||
} catch (Exception e) {
|
||||
// NOOP
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ArtifactCoordinates type(String type) {
|
||||
setType(type);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArtifactCoordinates qualifier(String qualifier) {
|
||||
if (CommonUtils.isValid(qualifier))
|
||||
this.versionQualifier = qualifier;
|
||||
else
|
||||
this.versionQualifier = "";
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArtifactCoordinates classifier(String classifier) {
|
||||
setClassifier(classifier);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArtifactCoordinates set(ArtifactCoordinates newCoordinates) {
|
||||
groupId(newCoordinates.getGroupId())
|
||||
.artifactId(newCoordinates.getArtifactId())
|
||||
.version(newCoordinates.getVersion())
|
||||
.type(newCoordinates.getType())
|
||||
.classifier(newCoordinates.getClassifier());
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArtifactCoordinates update(ArtifactCoordinates newCoordinates) {
|
||||
if (null != newCoordinates.getGroupId())
|
||||
groupId(newCoordinates.getGroupId());
|
||||
if (null != newCoordinates.getArtifactId())
|
||||
artifactId(newCoordinates.getArtifactId());
|
||||
if (null != newCoordinates.getVersion())
|
||||
version(newCoordinates.getVersion());
|
||||
if (null != newCoordinates.getType())
|
||||
type(newCoordinates.getType());
|
||||
if (null != newCoordinates.getClassifier())
|
||||
classifier(newCoordinates.getClassifier());
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isSnapshot() {
|
||||
return this.isSnapshot || SNAPSHOT_QUALIFIER.equals(this.versionQualifier);
|
||||
}
|
||||
|
||||
public void setSnapshot(boolean isSnapshot) {
|
||||
this.isSnapshot = isSnapshot;
|
||||
}
|
||||
public static final String SNAPSHOT_QUALIFIER = "SNAPSHOT";
|
||||
|
||||
public String getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
public void setGroupId(String groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
public String getArtifactId() {
|
||||
return artifactId;
|
||||
}
|
||||
public void setArtifactId(String artifactId) {
|
||||
this.artifactId = artifactId;
|
||||
}
|
||||
public String getVersion() {
|
||||
return this.calculateFinalVersion();
|
||||
}
|
||||
public void setVersion(String version) {
|
||||
if (!CommonUtils.isValid(version))
|
||||
this.version = DEFAULT_VERSION;
|
||||
else {
|
||||
String[] splitted = version.split("\\.");
|
||||
String[] splittedDefault = DEFAULT_VERSION.split("\\.");
|
||||
|
||||
String result = "";
|
||||
for (int i=0; i<splittedDefault.length; i++) {
|
||||
if (i != 0)
|
||||
result += ".";
|
||||
if ((splitted.length >= i+1) && CommonUtils.isValid(splitted[i]))
|
||||
result += splitted[i];
|
||||
else
|
||||
result += splittedDefault[i];
|
||||
}
|
||||
|
||||
this.version = result;
|
||||
}
|
||||
}
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
public String getClassifier() {
|
||||
return classifier;
|
||||
}
|
||||
public void setClassifier(String classifier) {
|
||||
this.classifier = classifier;
|
||||
}
|
||||
|
||||
public String getVersionPolicy() {
|
||||
return versionPolicy;
|
||||
}
|
||||
// x.y.z[-qualifier]
|
||||
public static final String VERSION_POLICY_CLEAR = "";
|
||||
// x.y.z-timestamp
|
||||
public static final String VERSION_POLICY_TIMESTAMPED = "timestamped";
|
||||
// x.y.z-yyMMddHHmmss
|
||||
public static final String VERSION_POLICY_DATED = "dated";
|
||||
// x.yyMMdd.HHmmss[-qualifier]
|
||||
public static final String VERSION_POLICY_DATED_EMBEDDED = "dated-embedded";
|
||||
|
||||
public void setVersionPolicy(String versionPolicy) {
|
||||
this.versionPolicy(versionPolicy);
|
||||
}
|
||||
public static ArtifactCoordinates fromUrl(String url) {
|
||||
if (!CommonUtils.isValid(url))
|
||||
return null;
|
||||
ArtifactCoordinates result = new ArtifactCoordinates();
|
||||
|
||||
String current = url;
|
||||
// trim protocol
|
||||
int index = url.lastIndexOf(':');
|
||||
if (index >= 0)
|
||||
current = current.substring(index + 1);
|
||||
|
||||
String[] fragments = current.split("/");
|
||||
if (fragments.length < 2)
|
||||
return null;
|
||||
|
||||
result.groupId(fragments[0]);
|
||||
result.artifactId(fragments[1]);
|
||||
|
||||
// split version on version itself and qualifier
|
||||
if (fragments.length > 2) {
|
||||
int ind = fragments[2].indexOf('-');
|
||||
if (ind > 0) {
|
||||
result.version(fragments[2].substring(0, ind));
|
||||
if (fragments[2].length() > ind + 1)
|
||||
result.qualifier(fragments[2].substring(ind + 1));
|
||||
} else {
|
||||
result.version(fragments[2]);
|
||||
}
|
||||
}
|
||||
|
||||
if (fragments.length > 3)
|
||||
result.type(fragments[3]);
|
||||
|
||||
if (fragments.length > 4)
|
||||
result.classifier(fragments[4]);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected String groupId;
|
||||
protected String artifactId;
|
||||
protected String version = "1.0";
|
||||
protected String type;
|
||||
protected String classifier;
|
||||
|
||||
protected String versionPolicy = VERSION_POLICY_CLEAR;
|
||||
|
||||
protected String versionQualifier = "";
|
||||
|
||||
protected String timestamp = "";
|
||||
|
||||
protected Calendar calendar = null;
|
||||
|
||||
protected boolean isSnapshot = false;
|
||||
|
||||
protected Set<String> allowedPolicies = new HashSet<>() {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
{
|
||||
add(VERSION_POLICY_CLEAR);
|
||||
add(VERSION_POLICY_DATED);
|
||||
add(VERSION_POLICY_DATED_EMBEDDED);
|
||||
add(VERSION_POLICY_TIMESTAMPED);
|
||||
}
|
||||
};
|
||||
|
||||
public ArtifactCoordinates groupId(String groupId) {
|
||||
setGroupId(groupId);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArtifactCoordinates artifactId(String artifactId) {
|
||||
setArtifactId(artifactId);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArtifactCoordinates versionPolicy(String versionPolicy) {
|
||||
if (this.allowedPolicies.contains(versionPolicy))
|
||||
this.versionPolicy = versionPolicy;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArtifactCoordinates version(String version) {
|
||||
this.versionQualifier = "";
|
||||
setVersion(version);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArtifactCoordinates timestampedVersion(String version) {
|
||||
this.version(version);
|
||||
this.timestamped();
|
||||
// versionQualifier = "-" + Calendar.getInstance().getTimeInMillis();
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArtifactCoordinates timestamp(String timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArtifactCoordinates timestamped() {
|
||||
return timestamped(Calendar.getInstance().getTimeInMillis() + "");
|
||||
}
|
||||
|
||||
public ArtifactCoordinates timestamped(String timestamp) {
|
||||
if (CommonUtils.isValid(timestamp)) {
|
||||
this.timestamp = timestamp;
|
||||
this.versionPolicy(VERSION_POLICY_TIMESTAMPED);
|
||||
} else {
|
||||
this.timestamp = "";
|
||||
this.versionPolicy(VERSION_POLICY_CLEAR);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArtifactCoordinates datedVersion(String version) {
|
||||
this.version(version);
|
||||
this.dated();
|
||||
// versionQualifier = "-" + Calendar.getInstance().getTimeInMillis();
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArtifactCoordinates dated() {
|
||||
this.calendar = Calendar.getInstance();
|
||||
versionPolicy(VERSION_POLICY_DATED);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArtifactCoordinates datedEmbeddedVersion(String version) {
|
||||
this.version(version);
|
||||
this.datedEmbedded();
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArtifactCoordinates datedEmbedded() {
|
||||
this.calendar = Calendar.getInstance();
|
||||
versionPolicy(VERSION_POLICY_DATED_EMBEDDED);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected String getResultQualifier() {
|
||||
if (isSnapshot)
|
||||
return "-" + SNAPSHOT_QUALIFIER;
|
||||
if (CommonUtils.isValid(this.versionQualifier))
|
||||
return "-" + this.versionQualifier;
|
||||
return "";
|
||||
}
|
||||
|
||||
protected String calculateFinalVersion() {
|
||||
if (VERSION_POLICY_TIMESTAMPED.equals(this.versionPolicy)) {
|
||||
if (!CommonUtils.isValid(this.timestamp))
|
||||
this.timestamp = Calendar.getInstance().getTimeInMillis() + "";
|
||||
return this.version + "-" + this.timestamp;
|
||||
}
|
||||
if (VERSION_POLICY_DATED.equals(this.versionPolicy)) {
|
||||
prepareCalendar();
|
||||
return this.version + "-" + ((new SimpleDateFormat("yyMMddHHmmss")).format(this.calendar.getTime()));
|
||||
}
|
||||
if (VERSION_POLICY_DATED_EMBEDDED.equals(this.versionPolicy)) {
|
||||
prepareCalendar();
|
||||
return this.version.split("\\.")[0]
|
||||
+ "."
|
||||
+ ((new SimpleDateFormat("yyMMdd.HHmmss")).format(this.calendar.getTime()))
|
||||
+ getResultQualifier();
|
||||
}
|
||||
return this.version + this.getResultQualifier();
|
||||
}
|
||||
|
||||
protected void prepareCalendar() {
|
||||
if (this.calendar == null)
|
||||
this.calendar = Calendar.getInstance();
|
||||
if (CommonUtils.isValid(this.timestamp)) {
|
||||
try {
|
||||
this.calendar.setTimeInMillis(Long.parseLong(this.timestamp));
|
||||
} catch (Exception e) {
|
||||
// NOOP
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ArtifactCoordinates type(String type) {
|
||||
setType(type);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArtifactCoordinates qualifier(String qualifier) {
|
||||
if (CommonUtils.isValid(qualifier))
|
||||
this.versionQualifier = qualifier;
|
||||
else
|
||||
this.versionQualifier = "";
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArtifactCoordinates classifier(String classifier) {
|
||||
setClassifier(classifier);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArtifactCoordinates set(ArtifactCoordinates newCoordinates) {
|
||||
groupId(newCoordinates.getGroupId())
|
||||
.artifactId(newCoordinates.getArtifactId())
|
||||
.version(newCoordinates.getVersion())
|
||||
.type(newCoordinates.getType())
|
||||
.classifier(newCoordinates.getClassifier());
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArtifactCoordinates update(ArtifactCoordinates newCoordinates) {
|
||||
if (null != newCoordinates.getGroupId())
|
||||
groupId(newCoordinates.getGroupId());
|
||||
if (null != newCoordinates.getArtifactId())
|
||||
artifactId(newCoordinates.getArtifactId());
|
||||
if (null != newCoordinates.getVersion())
|
||||
version(newCoordinates.getVersion());
|
||||
if (null != newCoordinates.getType())
|
||||
type(newCoordinates.getType());
|
||||
if (null != newCoordinates.getClassifier())
|
||||
classifier(newCoordinates.getClassifier());
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isSnapshot() {
|
||||
return this.isSnapshot || SNAPSHOT_QUALIFIER.equals(this.versionQualifier);
|
||||
}
|
||||
|
||||
public void setSnapshot(boolean isSnapshot) {
|
||||
this.isSnapshot = isSnapshot;
|
||||
}
|
||||
|
||||
public String getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public void setGroupId(String groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public String getArtifactId() {
|
||||
return artifactId;
|
||||
}
|
||||
|
||||
public void setArtifactId(String artifactId) {
|
||||
this.artifactId = artifactId;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return this.calculateFinalVersion();
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
if (!CommonUtils.isValid(version))
|
||||
this.version = DEFAULT_VERSION;
|
||||
else {
|
||||
String[] splitted = version.split("\\.");
|
||||
String[] splittedDefault = DEFAULT_VERSION.split("\\.");
|
||||
|
||||
String result = "";
|
||||
for (int i = 0; i < splittedDefault.length; i++) {
|
||||
if (i != 0)
|
||||
result += ".";
|
||||
if ((splitted.length >= i + 1) && CommonUtils.isValid(splitted[i]))
|
||||
result += splitted[i];
|
||||
else
|
||||
result += splittedDefault[i];
|
||||
}
|
||||
|
||||
this.version = result;
|
||||
}
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getClassifier() {
|
||||
return classifier;
|
||||
}
|
||||
|
||||
public void setClassifier(String classifier) {
|
||||
this.classifier = classifier;
|
||||
}
|
||||
|
||||
public String getVersionPolicy() {
|
||||
return versionPolicy;
|
||||
}
|
||||
|
||||
public void setVersionPolicy(String versionPolicy) {
|
||||
this.versionPolicy(versionPolicy);
|
||||
}
|
||||
|
||||
public String toAssetName() {
|
||||
String result = getArtifactId().concat("-").concat(getVersion());
|
||||
if (CommonUtils.isValid(getClassifier()))
|
||||
result = result.concat("-").concat(getClassifier());
|
||||
result = result.concat(".").concat(CommonUtils.getValid(getType(), DEFAULT_TYPE));
|
||||
return result;
|
||||
}
|
||||
|
||||
public String toRepositoryPath() {
|
||||
return String.format("%s/%s/%s/%s", getGroupId().replace('.', '/'), getArtifactId(), getVersion(),
|
||||
toAssetName());
|
||||
}
|
||||
|
||||
public String toMavenString() {
|
||||
return toString();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String result = String.format("%s/%s/%s", getGroupId(), getArtifactId(), getVersion());
|
||||
if (!Strings.isNullOrEmpty(type)) {
|
||||
result += "/" + type;
|
||||
if (!Strings.isNullOrEmpty(classifier))
|
||||
result += "/" + classifier;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String result = String.format("%s/%s/%s", getGroupId(), getArtifactId(), getVersion());
|
||||
if (!Strings.isNullOrEmpty(type)) {
|
||||
result += "/" + type;
|
||||
if (!Strings.isNullOrEmpty(classifier))
|
||||
result += "/" + classifier;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* test-producers
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -25,8 +25,11 @@
|
||||
*/
|
||||
package ru.entaxy.platform.core.artifact;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -34,56 +37,146 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ru.entaxy.esb.platform.runtime.base.connecting.generator.Generated;
|
||||
import ru.entaxy.platform.base.support.CommonUtils;
|
||||
import ru.entaxy.platform.core.artifact.annotation.ArtifactSupport;
|
||||
|
||||
public class Artifacts {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(Artifacts.class);
|
||||
|
||||
protected static final Map<String, Class<?>> supportClasses = new HashMap<>();
|
||||
private static final Logger log = LoggerFactory.getLogger(Artifacts.class);
|
||||
|
||||
public static final String DEFAULT_CLASSIFIER = "";
|
||||
|
||||
protected static final Map<String, Class<?>> supportClasses = new HashMap<>();
|
||||
|
||||
static {
|
||||
Artifacts.registerSupport(Blueprint.class);
|
||||
}
|
||||
|
||||
|
||||
public static final void registerSupport(Class<?> supportClass) {
|
||||
if (supportClass.isAnnotationPresent(ArtifactSupport.class)) {
|
||||
String artifactType = supportClass.getAnnotation(ArtifactSupport.class).supportedCategory();
|
||||
Artifacts.supportClasses.put(artifactType, supportClass);
|
||||
}
|
||||
}
|
||||
|
||||
public static final DefaultArtifact create(String category) {
|
||||
if (supportClasses.containsKey(category)) {
|
||||
Class<?> supportClass = supportClasses.get(category);
|
||||
try {
|
||||
Constructor<?> c = supportClass.getConstructor();
|
||||
Object instance = c.newInstance();
|
||||
if (DefaultArtifact.class.isAssignableFrom(instance.getClass()))
|
||||
return (DefaultArtifact) instance;
|
||||
} catch (NoSuchMethodException e) {
|
||||
log.error("Error creating artifact", e);
|
||||
} catch (SecurityException e) {
|
||||
log.error("Error creating artifact", e);
|
||||
} catch (InstantiationException e) {
|
||||
log.error("Error creating artifact", e);
|
||||
} catch (IllegalAccessException e) {
|
||||
log.error("Error creating artifact", e);
|
||||
} catch (IllegalArgumentException e) {
|
||||
log.error("Error creating artifact", e);
|
||||
} catch (InvocationTargetException e) {
|
||||
log.error("Error creating artifact", e);
|
||||
}
|
||||
}
|
||||
return new DefaultArtifact();
|
||||
}
|
||||
|
||||
public static final DefaultArtifact fromGenerated(Generated generated) {
|
||||
DefaultArtifact result = Artifacts.create(generated.getType());
|
||||
if (result != null)
|
||||
result.setContent(generated.getObject());
|
||||
return result;
|
||||
}
|
||||
|
||||
public static final DefaultArtifact fromFile(File source, String fileRoot) {
|
||||
return fromFile(source, fileRoot, null);
|
||||
}
|
||||
|
||||
public static final DefaultArtifact fromFile(File source, String fileRoot, String category) {
|
||||
String ownPath = source.getAbsolutePath().replace('\\', '/').substring(fileRoot.length());
|
||||
if (ownPath.startsWith("/"))
|
||||
ownPath = ownPath.substring(1);
|
||||
log.debug("Artifacts.fromFile: \n\tFILE: [{}]\n\tPATH: [{}]", source.getAbsolutePath(), ownPath);
|
||||
|
||||
String currentPath = ownPath;
|
||||
|
||||
int index = currentPath.lastIndexOf('/');
|
||||
if (index < 0) {
|
||||
log.error("Filename not found in path [{}]", ownPath);
|
||||
return null;
|
||||
}
|
||||
String fileName = currentPath.substring(index + 1);
|
||||
currentPath = currentPath.substring(0, index);
|
||||
|
||||
index = currentPath.lastIndexOf('/');
|
||||
if (index < 0) {
|
||||
log.error("version not found in path [{}]", ownPath);
|
||||
return null;
|
||||
}
|
||||
String version = currentPath.substring(index + 1);
|
||||
currentPath = currentPath.substring(0, index);
|
||||
|
||||
index = currentPath.lastIndexOf('/');
|
||||
if (index < 0) {
|
||||
log.error("artifactId not found in path [{}]", ownPath);
|
||||
return null;
|
||||
}
|
||||
String artifactId = currentPath.substring(index + 1);
|
||||
currentPath = currentPath.substring(0, index);
|
||||
|
||||
String groupId = currentPath.replaceAll("/", ".");
|
||||
|
||||
index = fileName.lastIndexOf('.');
|
||||
if (index < 0) {
|
||||
log.error("extension not found in path [{}]", ownPath);
|
||||
return null;
|
||||
}
|
||||
String extension = fileName.substring(index + 1);
|
||||
|
||||
String classifier = category;
|
||||
if (!CommonUtils.isValid(category)) {
|
||||
String fileNamePrefix = artifactId + "-" + version;
|
||||
index = fileName.indexOf(fileNamePrefix);
|
||||
if (index < 0)
|
||||
return null;
|
||||
classifier = fileName.substring(index + fileNamePrefix.length() + 1, fileName.lastIndexOf('.'));
|
||||
}
|
||||
|
||||
if (!CommonUtils.isValid(classifier))
|
||||
classifier = DEFAULT_CLASSIFIER;
|
||||
|
||||
log.debug("Artifacts.fromFile:" +
|
||||
"\n\tCOORDINATES:\n\tgroupId: [{}]\n\tartifactId: [{}]\n\tversion: [{}]\n\textension: [{}]\n\tclassifier: [{}]",
|
||||
groupId,
|
||||
artifactId,
|
||||
version,
|
||||
extension,
|
||||
classifier);
|
||||
|
||||
if (!CommonUtils.isValid(groupId) || !CommonUtils.isValid(artifactId) || !CommonUtils.isValid(version)
|
||||
|| !CommonUtils.isValid(extension))
|
||||
return null;
|
||||
|
||||
DefaultArtifact result = create(classifier);
|
||||
|
||||
if (result != null) {
|
||||
result.getCoordinates().groupId(groupId).artifactId(artifactId).version(version).type(extension)
|
||||
.classifier(classifier);
|
||||
byte[] contents;
|
||||
try {
|
||||
contents = Files.readAllBytes(source.toPath());
|
||||
result.setContent(contents);
|
||||
} catch (IOException e) {
|
||||
log.error("Error setting artifact contents", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static {
|
||||
Artifacts.registerSupport(Blueprint.class);
|
||||
}
|
||||
|
||||
|
||||
public static final void registerSupport(Class<?> supportClass) {
|
||||
if (supportClass.isAnnotationPresent(ArtifactSupport.class)) {
|
||||
String artifactType = supportClass.getAnnotation(ArtifactSupport.class).supportedCategory();
|
||||
Artifacts.supportClasses.put(artifactType, supportClass);
|
||||
}
|
||||
}
|
||||
|
||||
public static final DefaultArtifact create(String category) {
|
||||
if (supportClasses.containsKey(category)) {
|
||||
Class<?> supportClass = supportClasses.get(category);
|
||||
try {
|
||||
Constructor<?> c = supportClass.getConstructor();
|
||||
Object instance = c.newInstance();
|
||||
if (DefaultArtifact.class.isAssignableFrom(instance.getClass()))
|
||||
return (DefaultArtifact)instance;
|
||||
} catch (NoSuchMethodException e) {
|
||||
log.error("Error creating artifact", e);
|
||||
} catch (SecurityException e) {
|
||||
log.error("Error creating artifact", e);
|
||||
} catch (InstantiationException e) {
|
||||
log.error("Error creating artifact", e);
|
||||
} catch (IllegalAccessException e) {
|
||||
log.error("Error creating artifact", e);
|
||||
} catch (IllegalArgumentException e) {
|
||||
log.error("Error creating artifact", e);
|
||||
} catch (InvocationTargetException e) {
|
||||
log.error("Error creating artifact", e);
|
||||
}
|
||||
}
|
||||
return new DefaultArtifact();
|
||||
}
|
||||
|
||||
public static final DefaultArtifact fromGenerated(Generated generated) {
|
||||
DefaultArtifact result = Artifacts.create(generated.getType());
|
||||
if (result != null)
|
||||
result.setContent(generated.getObject());
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -35,81 +35,83 @@ import org.w3c.dom.Document;
|
||||
import ru.entaxy.platform.base.support.xml.CommonXMLUtils;
|
||||
import ru.entaxy.platform.core.artifact.annotation.ArtifactSupport;
|
||||
|
||||
@ArtifactSupport(supportedCategory = Artifact.ARTIFACT_CATEGORY_BLUEPRINT
|
||||
, supportedContentClasses = {String.class, Document.class, byte[].class}
|
||||
, defaultArtifactClassifier = Artifact.ARTIFACT_CATEGORY_BLUEPRINT
|
||||
, defaultArtifactType = "xml")
|
||||
@ArtifactSupport(supportedCategory = Artifact.ARTIFACT_CATEGORY_BLUEPRINT,
|
||||
supportedContentClasses = {String.class, Document.class, byte[].class},
|
||||
defaultArtifactClassifier = Artifact.ARTIFACT_CATEGORY_BLUEPRINT, defaultArtifactType = "xml")
|
||||
public class Blueprint extends DefaultArtifact implements Manifested {
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(Blueprint.class);
|
||||
|
||||
public static final String ARTIFACT_CATEGORY_BLUEPRINT = "blueprint";
|
||||
|
||||
protected BlueprintManifest manifest = null;
|
||||
private final static Logger log = LoggerFactory.getLogger(Blueprint.class);
|
||||
|
||||
@Override
|
||||
public void setContent(Object content) {
|
||||
super.setContent(content);
|
||||
if (this.content.getClass().equals(byte[].class)) {
|
||||
String s = new String((byte[])this.content, StandardCharsets.UTF_8);
|
||||
this.content = s;
|
||||
}
|
||||
if (this.content.getClass().equals(String.class)) {
|
||||
try {
|
||||
Document d = CommonXMLUtils.parseString(false, (String)this.content);
|
||||
this.content = d;
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArtifactManifest getManifest() {
|
||||
if (this.manifest == null)
|
||||
this.manifest = new BlueprintManifest(this);
|
||||
if (this.content instanceof Document)
|
||||
this.manifest.load((Document)this.content);
|
||||
return this.manifest;
|
||||
}
|
||||
public static final String ARTIFACT_CATEGORY_BLUEPRINT = "blueprint";
|
||||
|
||||
protected BlueprintManifest manifest = null;
|
||||
|
||||
@Override
|
||||
public void setContent(Object content) {
|
||||
super.setContent(content);
|
||||
if (this.content.getClass().equals(byte[].class)) {
|
||||
String s = new String((byte[]) this.content, StandardCharsets.UTF_8);
|
||||
this.content = s;
|
||||
}
|
||||
if (this.content.getClass().equals(String.class)) {
|
||||
try {
|
||||
Document d = CommonXMLUtils.parseString(false, (String) this.content);
|
||||
this.content = d;
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArtifactManifest getManifest() {
|
||||
if (this.manifest == null)
|
||||
this.manifest = new BlueprintManifest(this);
|
||||
if (this.content instanceof Document)
|
||||
this.manifest.load((Document) this.content);
|
||||
return this.manifest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toFile(File destination) {
|
||||
if (this.content instanceof String)
|
||||
super.toFile(destination);
|
||||
else if (this.content instanceof Document) {
|
||||
Document doc = (Document) this.content;
|
||||
try {
|
||||
asByteArray();
|
||||
CommonXMLUtils.saveDocument(doc, destination);
|
||||
} catch (Exception e) {
|
||||
log.error("Error saving to file", e);
|
||||
}
|
||||
} else if (this.content instanceof byte[]) {
|
||||
// TODO to be implemented
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
if (this.content instanceof byte[])
|
||||
return (byte[]) this.content;
|
||||
if (this.content instanceof String)
|
||||
return ((String) this.content).getBytes();
|
||||
if (this.content instanceof Document)
|
||||
try {
|
||||
Document doc = (Document) this.content;
|
||||
|
||||
// make sure manifest exists
|
||||
getManifest();
|
||||
|
||||
if (!this.manifest.isLoaded())
|
||||
this.manifest.load(doc);
|
||||
this.manifest.save(doc);
|
||||
return CommonXMLUtils.doc2string(doc).getBytes();
|
||||
} catch (Exception e) {
|
||||
log.error("Error getting as byte[]: " + this.getCoordinates().toString(), e);
|
||||
}
|
||||
return new byte[] {};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toFile(File destination) {
|
||||
if (this.content instanceof String)
|
||||
super.toFile(destination);
|
||||
else if (this.content instanceof Document) {
|
||||
Document doc = (Document)this.content;
|
||||
try {
|
||||
asByteArray();
|
||||
CommonXMLUtils.saveDocument(doc, destination);
|
||||
} catch (Exception e) {
|
||||
log.error("Error saving to file", e);
|
||||
}
|
||||
}
|
||||
else if (this.content instanceof byte[]) {
|
||||
// TODO to be implemented
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
if (this.content instanceof byte[])
|
||||
return (byte[])this.content;
|
||||
if (this.content instanceof String)
|
||||
return ((String)this.content).getBytes();
|
||||
if (this.content instanceof Document)
|
||||
try {
|
||||
Document doc = (Document)this.content;
|
||||
if (!this.manifest.isLoaded())
|
||||
this.manifest.load(doc);
|
||||
this.manifest.save(doc);
|
||||
return CommonXMLUtils.doc2string(doc).getBytes();
|
||||
} catch (Exception e) {
|
||||
log.error("Error getting as byte[]: " + this.getCoordinates().toString(), e);
|
||||
}
|
||||
return new byte[] {};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* test-producers
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -29,7 +29,6 @@ import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -44,144 +43,145 @@ import ru.entaxy.platform.core.artifact.impl.CapabilityDescriptorImpl;
|
||||
|
||||
public class DefaultArtifact implements Artifact {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(DefaultArtifact.class);
|
||||
|
||||
protected ArtifactCoordinates coordinates;
|
||||
private static final Logger log = LoggerFactory.getLogger(DefaultArtifact.class);
|
||||
|
||||
protected ArtifactSupport artifactSupport = null;
|
||||
|
||||
protected Object content = null;
|
||||
|
||||
protected String category = Artifact.ARTIFACT_CATEGORY_UNKNOWN;
|
||||
|
||||
protected Map<String, Object> properties = new HashMap<>();
|
||||
|
||||
protected List<Class<?>> supportedContentClasses = new ArrayList<>();
|
||||
|
||||
protected Map<String, CapabilityDescriptorImpl> requiredCapabilities = new HashMap<>();
|
||||
protected Map<String, CapabilityDescriptorImpl> providedCapabilities = new HashMap<>();
|
||||
|
||||
public DefaultArtifact() {
|
||||
this.coordinates = new ArtifactCoordinates();
|
||||
this.artifactSupport = this.getClass().getAnnotation(ArtifactSupport.class);
|
||||
initArtifact();
|
||||
}
|
||||
|
||||
protected void initArtifact() {
|
||||
if (artifactSupport != null) {
|
||||
this.coordinates.type(artifactSupport.defaultArtifactType());
|
||||
this.coordinates.classifier(artifactSupport.defaultArtifactClassifier());
|
||||
this.setCategory(artifactSupport.supportedCategory());
|
||||
if (this.artifactSupport.supportedContentClasses() != null)
|
||||
for (int i=0; i<this.artifactSupport.supportedContentClasses().length; i++)
|
||||
this.supportedContentClasses.add(this.artifactSupport.supportedContentClasses()[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArtifactCoordinates getCoordinates() {
|
||||
return coordinates;
|
||||
}
|
||||
protected ArtifactCoordinates coordinates;
|
||||
|
||||
public Object getContent() {
|
||||
return content;
|
||||
}
|
||||
protected ArtifactSupport artifactSupport = null;
|
||||
|
||||
public void setContent(Object content) {
|
||||
if (content == null)
|
||||
setNullContent();
|
||||
else {
|
||||
if (artifactSupport != null) {
|
||||
checkSetContent(content);
|
||||
} else
|
||||
this.content = content;
|
||||
}
|
||||
}
|
||||
|
||||
protected void setNullContent() {
|
||||
this.content = null;
|
||||
}
|
||||
|
||||
protected void checkSetContent(Object content) {
|
||||
// TODO throw exception if content suites none of the supported classes
|
||||
|
||||
if (this.supportedContentClasses.contains(content.getClass()))
|
||||
this.content = content;
|
||||
|
||||
/*
|
||||
* Class<?>[] supportedContentTypes = Arrays.copyOf(
|
||||
* this.artifactSupport.supportedContentClasses(),
|
||||
* this.artifactSupport.supportedContentClasses().length); for (int i=0;
|
||||
* i<supportedContentTypes.length; i++) { if
|
||||
* (supportedContentTypes[i].isAssignableFrom(content.getClass())) this.content
|
||||
* = content; break; }
|
||||
*/ }
|
||||
|
||||
@Override
|
||||
public String getCategory() {
|
||||
return this.category;
|
||||
}
|
||||
protected Object content = null;
|
||||
|
||||
public void setCategory(String category) {
|
||||
if (!Strings.isNullOrEmpty(category))
|
||||
this.category = category;
|
||||
else
|
||||
this.category = Artifact.ARTIFACT_CATEGORY_UNKNOWN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toFile(File destination) {
|
||||
if (this.content != null) {
|
||||
try (FileWriter writer = new FileWriter(destination)) {
|
||||
writer.write(this.content.toString());
|
||||
} catch (IOException e) {
|
||||
log.error("Error writing to file", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
protected String category = Artifact.ARTIFACT_CATEGORY_UNKNOWN;
|
||||
|
||||
@Override
|
||||
public CapabilityDescriptor provideCapability(String namespace) {
|
||||
if (!this.providedCapabilities.containsKey(namespace))
|
||||
this.providedCapabilities.put(namespace, new CapabilityDescriptorImpl(namespace));
|
||||
return this.providedCapabilities.get(namespace);
|
||||
}
|
||||
protected Map<String, Object> properties = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public CapabilityDescriptor requireCapability(String namespace) {
|
||||
if (!this.requiredCapabilities.containsKey(namespace))
|
||||
this.requiredCapabilities.put(namespace, new CapabilityDescriptorImpl(namespace));
|
||||
return this.requiredCapabilities.get(namespace);
|
||||
}
|
||||
|
||||
protected String getRequiredCapabilitiesValue() {
|
||||
return getCapabilitiesValue(requiredCapabilities);
|
||||
}
|
||||
protected List<Class<?>> supportedContentClasses = new ArrayList<>();
|
||||
|
||||
protected String getProvidedCapabilitiesValue() {
|
||||
return getCapabilitiesValue(providedCapabilities);
|
||||
}
|
||||
|
||||
protected String getCapabilitiesValue(Map<String, CapabilityDescriptorImpl> data) {
|
||||
String result = "";
|
||||
for (Map.Entry<String, CapabilityDescriptorImpl> entry: data.entrySet()) {
|
||||
if (!result.isEmpty())
|
||||
result += ",";
|
||||
result += entry.getKey();
|
||||
String attributes = entry.getValue().getAttributesAsString();
|
||||
if (!attributes.isEmpty())
|
||||
result += ";" + attributes;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
protected Map<String, CapabilityDescriptorImpl> requiredCapabilities = new HashMap<>();
|
||||
protected Map<String, CapabilityDescriptorImpl> providedCapabilities = new HashMap<>();
|
||||
|
||||
public DefaultArtifact() {
|
||||
this.coordinates = new ArtifactCoordinates();
|
||||
this.artifactSupport = this.getClass().getAnnotation(ArtifactSupport.class);
|
||||
initArtifact();
|
||||
}
|
||||
|
||||
protected void initArtifact() {
|
||||
if (artifactSupport != null) {
|
||||
this.coordinates.type(artifactSupport.defaultArtifactType());
|
||||
this.coordinates.classifier(artifactSupport.defaultArtifactClassifier());
|
||||
this.setCategory(artifactSupport.supportedCategory());
|
||||
if (this.artifactSupport.supportedContentClasses() != null)
|
||||
for (int i = 0; i < this.artifactSupport.supportedContentClasses().length; i++)
|
||||
this.supportedContentClasses.add(this.artifactSupport.supportedContentClasses()[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArtifactCoordinates getCoordinates() {
|
||||
return coordinates;
|
||||
}
|
||||
|
||||
public Object getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(Object content) {
|
||||
if (content == null)
|
||||
setNullContent();
|
||||
else {
|
||||
if (artifactSupport != null) {
|
||||
checkSetContent(content);
|
||||
} else
|
||||
this.content = content;
|
||||
}
|
||||
}
|
||||
|
||||
protected void setNullContent() {
|
||||
this.content = null;
|
||||
}
|
||||
|
||||
protected void checkSetContent(Object content) {
|
||||
// TODO throw exception if content suites none of the supported classes
|
||||
|
||||
if (this.supportedContentClasses.contains(content.getClass())) {
|
||||
this.content = content;
|
||||
} else {
|
||||
for (Class<?> clazz : this.supportedContentClasses) {
|
||||
if (clazz.isInstance(content)) {
|
||||
this.content = content;
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCategory() {
|
||||
return this.category;
|
||||
}
|
||||
|
||||
public void setCategory(String category) {
|
||||
if (!Strings.isNullOrEmpty(category))
|
||||
this.category = category;
|
||||
else
|
||||
this.category = Artifact.ARTIFACT_CATEGORY_UNKNOWN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toFile(File destination) {
|
||||
if (this.content != null) {
|
||||
try (FileWriter writer = new FileWriter(destination)) {
|
||||
writer.write(this.content.toString());
|
||||
} catch (IOException e) {
|
||||
log.error("Error writing to file", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CapabilityDescriptor provideCapability(String namespace) {
|
||||
if (!this.providedCapabilities.containsKey(namespace))
|
||||
this.providedCapabilities.put(namespace, new CapabilityDescriptorImpl(namespace));
|
||||
return this.providedCapabilities.get(namespace);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CapabilityDescriptor requireCapability(String namespace) {
|
||||
if (!this.requiredCapabilities.containsKey(namespace))
|
||||
this.requiredCapabilities.put(namespace, new CapabilityDescriptorImpl(namespace));
|
||||
return this.requiredCapabilities.get(namespace);
|
||||
}
|
||||
|
||||
protected String getRequiredCapabilitiesValue() {
|
||||
return getCapabilitiesValue(requiredCapabilities);
|
||||
}
|
||||
|
||||
protected String getProvidedCapabilitiesValue() {
|
||||
return getCapabilitiesValue(providedCapabilities);
|
||||
}
|
||||
|
||||
protected String getCapabilitiesValue(Map<String, CapabilityDescriptorImpl> data) {
|
||||
String result = "";
|
||||
for (Map.Entry<String, CapabilityDescriptorImpl> entry : data.entrySet()) {
|
||||
if (!result.isEmpty())
|
||||
result += ",";
|
||||
result += entry.getKey();
|
||||
String attributes = entry.getValue().getAttributesAsString();
|
||||
if (!attributes.isEmpty())
|
||||
result += ";" + attributes;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* test-producers
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* test-producers
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -130,4 +130,10 @@ public class CapabilityDescriptorImpl implements CapabilityDescriptor {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getRawAttributes() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -30,7 +30,6 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.karaf.bundle.command.Install;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -38,268 +37,308 @@ import ru.entaxy.platform.core.artifact.DeployedArtifact;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.InstallationResult;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.Installer;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.typed.BundleInstaller;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.typed.DefaultTypedInstallerFactory;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.typed.TypedInstaller;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.typed.impl.TypedInstallerHelper;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.typed.TypedInstallerManager;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.typed.impl.HelperCreator;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.typed.impl.TypedInstallerHelperAware;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.typed.impl.TypedInstallerHelperImpl;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.typed.impl.TypedInstallerImpl;
|
||||
import ru.entaxy.platform.core.artifact.legacy.BundleController;
|
||||
|
||||
public abstract class AbstractInstaller<T extends Installer<T>, H extends TypedInstallerHelper>
|
||||
implements BundleController {
|
||||
public abstract class AbstractInstaller<T extends Installer<T>, H extends TypedInstallerHelperImpl>
|
||||
implements BundleController {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(AbstractInstaller.class);
|
||||
|
||||
protected DeployedArtifact artifact = null;
|
||||
protected String sourceLocation = null;
|
||||
protected String bundleName = null;
|
||||
|
||||
protected Map<String, Class<? extends TypedInstallerImpl>> typedInstallerClasses = new HashMap<>();
|
||||
protected Map<Class<? extends TypedInstallerImpl>, Class<? extends H>> typedHelperClasses = new HashMap<>();
|
||||
private static final Logger log = LoggerFactory.getLogger(AbstractInstaller.class);
|
||||
|
||||
|
||||
// for BundleInstaller implementation
|
||||
protected BundleInstaller bundleInstaller = null;
|
||||
|
||||
protected TypedInstallerImpl typedInstaller = null;
|
||||
static {
|
||||
TypedInstallerManager.register(DefaultTypedInstallerFactory.getInstance());
|
||||
}
|
||||
|
||||
protected AbstractInstaller() {
|
||||
this.typedInstallerClasses = new HashMap<>();
|
||||
this.typedHelperClasses = new HashMap<>();
|
||||
}
|
||||
protected DeployedArtifact artifact = null;
|
||||
protected String sourceLocation = null;
|
||||
protected String bundleName = null;
|
||||
|
||||
protected void doCreateTypedInstaller(Class<? extends TypedInstallerImpl> clazz) {
|
||||
Constructor<?> constructor;
|
||||
try {
|
||||
constructor = clazz.getConstructor();
|
||||
this.typedInstaller = (TypedInstallerImpl)constructor.newInstance();
|
||||
} catch (NoSuchMethodException | SecurityException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (InstantiationException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IllegalArgumentException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected void createTypedInstaller() {
|
||||
Class<? extends TypedInstallerImpl> clazz =
|
||||
artifact==null
|
||||
?null
|
||||
:typedInstallerClasses.get(artifact.getArtifact().getCategory());
|
||||
if (clazz == null)
|
||||
// TODO throw exception
|
||||
return;
|
||||
doCreateTypedInstaller(clazz);
|
||||
if (this.typedInstaller != null) {
|
||||
initTypedInstaller();
|
||||
}
|
||||
}
|
||||
// protected Map<String, Class<? extends TypedInstallerImpl>> typedInstallerClasses = new
|
||||
// HashMap<>();
|
||||
protected Map<Class<? extends TypedInstaller>, Class<? extends H>> typedHelperClasses = new HashMap<>();
|
||||
|
||||
protected void findTypedInstaller(Class<?> type) {
|
||||
Class<? extends TypedInstallerImpl> clazz = null;
|
||||
for (Class<? extends TypedInstallerImpl> cl : typedInstallerClasses.values())
|
||||
if ((cl != null) && type.isAssignableFrom(cl)) {
|
||||
clazz = cl;
|
||||
break;
|
||||
}
|
||||
if (clazz == null)
|
||||
// TODO throw exception
|
||||
return;
|
||||
doCreateTypedInstaller(clazz);
|
||||
if (this.typedInstaller != null) {
|
||||
initTypedInstaller();
|
||||
}
|
||||
}
|
||||
|
||||
protected H createHelper() {
|
||||
Class<? extends H> clazz = typedHelperClasses.get(typedInstaller.getClass());
|
||||
if (clazz == null)
|
||||
return createDefaultHelper();
|
||||
Constructor<?> constructor;
|
||||
String errorMessage = "Error creating typed installer helper";
|
||||
try {
|
||||
constructor = clazz.getConstructor();
|
||||
return (H)constructor.newInstance();
|
||||
} catch (NoSuchMethodException | SecurityException e) {
|
||||
log.error(errorMessage, e);
|
||||
} catch (InstantiationException e) {
|
||||
log.error(errorMessage, e);
|
||||
} catch (IllegalAccessException e) {
|
||||
log.error(errorMessage, e);
|
||||
} catch (IllegalArgumentException e) {
|
||||
log.error(errorMessage, e);
|
||||
} catch (InvocationTargetException e) {
|
||||
log.error(errorMessage, e);
|
||||
}
|
||||
|
||||
return createDefaultHelper();
|
||||
}
|
||||
|
||||
protected abstract H createDefaultHelper();
|
||||
|
||||
protected void refreshTypedInstaller() {
|
||||
this.typedInstaller.clearInstaller();
|
||||
this.typedInstaller.setArtifact(this.artifact);
|
||||
this.typedInstaller.setSourceLocation(this.sourceLocation);
|
||||
this.typedInstaller.setBundleName(this.bundleName);
|
||||
}
|
||||
|
||||
protected void initTypedInstaller() {
|
||||
refreshTypedInstaller();
|
||||
|
||||
H helper = createHelper();
|
||||
initHelper(helper);
|
||||
this.typedInstaller.setHelper(helper);
|
||||
}
|
||||
|
||||
protected void initHelper(H helper) {
|
||||
|
||||
};
|
||||
|
||||
public <S extends TypedInstaller> S typed(Class<S> type) {
|
||||
if (this.typedInstaller == null)
|
||||
createTypedInstaller();
|
||||
if (this.typedInstaller == null)
|
||||
findTypedInstaller(type);
|
||||
if (this.typedInstaller == null)
|
||||
// TODO throw exception
|
||||
return null;
|
||||
if (!type.isAssignableFrom(this.typedInstaller.getClass()))
|
||||
// TODO throw exception
|
||||
return null;
|
||||
return type.cast(this.typedInstaller);
|
||||
}
|
||||
// for BundleInstaller implementation
|
||||
protected BundleInstaller bundleInstaller = null;
|
||||
|
||||
public InstallationResult install() {
|
||||
if (typedInstaller == null) {
|
||||
createTypedInstaller();
|
||||
}
|
||||
if (typedInstaller != null)
|
||||
return typedInstaller.install();
|
||||
return null;
|
||||
}
|
||||
protected TypedInstaller typedInstaller = null;
|
||||
|
||||
public InstallationResult uninstall() {
|
||||
if (typedInstaller == null) {
|
||||
createTypedInstaller();
|
||||
}
|
||||
if (typedInstaller != null)
|
||||
return typedInstaller.uninstall();
|
||||
return null;
|
||||
}
|
||||
protected AbstractInstaller() {
|
||||
// this.typedInstallerClasses = new HashMap<>();
|
||||
this.typedHelperClasses = new HashMap<>();
|
||||
}
|
||||
|
||||
public T artifact(DeployedArtifact artifact) {
|
||||
setArtifact(artifact);
|
||||
return (T)this;
|
||||
}
|
||||
protected abstract Class<H> getHelperClass();
|
||||
|
||||
public T sourceLocation(String sourceLocation) {
|
||||
setSourceLocation(sourceLocation);
|
||||
return (T)this;
|
||||
}
|
||||
|
||||
public void setArtifact(DeployedArtifact artifact) {
|
||||
this.artifact = artifact;
|
||||
}
|
||||
protected void doCreateTypedInstaller(Class<? extends TypedInstallerImpl> clazz) {
|
||||
Constructor<?> constructor;
|
||||
try {
|
||||
constructor = clazz.getConstructor();
|
||||
this.typedInstaller = (TypedInstallerImpl) constructor.newInstance();
|
||||
} catch (NoSuchMethodException | SecurityException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (InstantiationException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IllegalArgumentException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void setSourceLocation(String sourceLocation) {
|
||||
this.sourceLocation = sourceLocation;
|
||||
}
|
||||
protected void createTypedInstaller() {
|
||||
if (artifact == null || artifact.getArtifact() == null)
|
||||
return;
|
||||
this.typedInstaller = TypedInstallerManager.create(this, artifact.getArtifact().getCategory());
|
||||
if (this.typedInstaller != null) {
|
||||
initTypedInstaller();
|
||||
}
|
||||
}
|
||||
|
||||
public T bundleName(String bundleName) {
|
||||
setBundleName(bundleName);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public void setBundleName(String bundleName) {
|
||||
this.bundleName = bundleName;
|
||||
}
|
||||
/*
|
||||
protected void createTypedInstaller() {
|
||||
Class<? extends TypedInstallerImpl> clazz =
|
||||
artifact == null
|
||||
? null
|
||||
: typedInstallerClasses.get(artifact.getArtifact().getCategory());
|
||||
if (clazz == null)
|
||||
// TODO throw exception
|
||||
return;
|
||||
doCreateTypedInstaller(clazz);
|
||||
if (this.typedInstaller != null) {
|
||||
initTypedInstaller();
|
||||
}
|
||||
}
|
||||
*/
|
||||
protected void findTypedInstaller(Class<? extends TypedInstaller> type) {
|
||||
this.typedInstaller = TypedInstallerManager.create(this, type);
|
||||
if (this.typedInstaller != null) {
|
||||
initTypedInstaller();
|
||||
}
|
||||
}
|
||||
|
||||
public BundleController bundleController() {
|
||||
return (BundleController) this;
|
||||
}
|
||||
/*
|
||||
protected void findTypedInstaller(Class<?> type) {
|
||||
Class<? extends TypedInstallerImpl> clazz = null;
|
||||
for (Class<? extends TypedInstallerImpl> cl : typedInstallerClasses.values())
|
||||
if ((cl != null) && type.isAssignableFrom(cl)) {
|
||||
clazz = cl;
|
||||
break;
|
||||
}
|
||||
if (clazz == null)
|
||||
// TODO throw exception
|
||||
return;
|
||||
doCreateTypedInstaller(clazz);
|
||||
if (this.typedInstaller != null) {
|
||||
initTypedInstaller();
|
||||
}
|
||||
}
|
||||
*/
|
||||
protected H createHelper() {
|
||||
Class<? extends H> clazz = typedHelperClasses.get(typedInstaller.getClass());
|
||||
if (clazz == null) {
|
||||
for (Class<? extends TypedInstaller> typedClass : typedHelperClasses.keySet())
|
||||
if (typedClass.isInstance(typedInstaller)) {
|
||||
clazz = typedHelperClasses.get(typedClass);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (clazz == null) {
|
||||
// check installer itself
|
||||
if (typedInstaller instanceof HelperCreator)
|
||||
return ((HelperCreator) typedInstaller).createHelper(getHelperClass());
|
||||
}
|
||||
if (clazz == null)
|
||||
return createDefaultHelper();
|
||||
Constructor<?> constructor;
|
||||
String errorMessage = "Error creating typed installer helper";
|
||||
try {
|
||||
constructor = clazz.getConstructor();
|
||||
return (H) constructor.newInstance();
|
||||
} catch (NoSuchMethodException | SecurityException e) {
|
||||
log.error(errorMessage, e);
|
||||
} catch (InstantiationException e) {
|
||||
log.error(errorMessage, e);
|
||||
} catch (IllegalAccessException e) {
|
||||
log.error(errorMessage, e);
|
||||
} catch (IllegalArgumentException e) {
|
||||
log.error(errorMessage, e);
|
||||
} catch (InvocationTargetException e) {
|
||||
log.error(errorMessage, e);
|
||||
}
|
||||
|
||||
protected BundleInstaller createBundleInstaller() {
|
||||
return typed(BundleInstaller.class);
|
||||
}
|
||||
|
||||
protected void initBundleInstaller() {
|
||||
if (this.bundleInstaller == null)
|
||||
this.bundleInstaller = createBundleInstaller();
|
||||
}
|
||||
|
||||
protected void clear() {
|
||||
this.artifact = null;
|
||||
this.sourceLocation = null;
|
||||
this.bundleName = null;
|
||||
}
|
||||
|
||||
/*
|
||||
* BundleController implementation
|
||||
*/
|
||||
return createDefaultHelper();
|
||||
}
|
||||
|
||||
protected abstract H createDefaultHelper();
|
||||
|
||||
protected void refreshTypedInstaller() {
|
||||
this.typedInstaller.clearInstaller();
|
||||
this.typedInstaller.setArtifact(this.artifact);
|
||||
this.typedInstaller.setSourceLocation(this.sourceLocation);
|
||||
this.typedInstaller.setTypedName(this.bundleName);
|
||||
}
|
||||
|
||||
protected void initTypedInstaller() {
|
||||
refreshTypedInstaller();
|
||||
|
||||
H helper = createHelper();
|
||||
initHelper(helper);
|
||||
if (this.typedInstaller instanceof TypedInstallerHelperAware)
|
||||
((TypedInstallerHelperAware) this.typedInstaller).setHelper(helper);
|
||||
}
|
||||
|
||||
protected void initHelper(H helper) {
|
||||
|
||||
};
|
||||
|
||||
public <S extends TypedInstaller> S typed(Class<S> type) {
|
||||
if (this.typedInstaller == null)
|
||||
createTypedInstaller();
|
||||
if (this.typedInstaller == null)
|
||||
findTypedInstaller(type);
|
||||
if (this.typedInstaller == null)
|
||||
// TODO throw exception
|
||||
return null;
|
||||
if (!type.isAssignableFrom(this.typedInstaller.getClass()))
|
||||
// TODO throw exception
|
||||
return null;
|
||||
return type.cast(this.typedInstaller);
|
||||
}
|
||||
|
||||
public InstallationResult install() {
|
||||
if (typedInstaller == null) {
|
||||
createTypedInstaller();
|
||||
}
|
||||
if (typedInstaller != null)
|
||||
return typedInstaller.install();
|
||||
return null;
|
||||
}
|
||||
|
||||
public InstallationResult uninstall() {
|
||||
if (typedInstaller == null) {
|
||||
createTypedInstaller();
|
||||
}
|
||||
if (typedInstaller != null)
|
||||
return typedInstaller.uninstall();
|
||||
return null;
|
||||
}
|
||||
|
||||
public T artifact(DeployedArtifact artifact) {
|
||||
setArtifact(artifact);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T sourceLocation(String sourceLocation) {
|
||||
setSourceLocation(sourceLocation);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public void setArtifact(DeployedArtifact artifact) {
|
||||
this.artifact = artifact;
|
||||
}
|
||||
|
||||
public void setSourceLocation(String sourceLocation) {
|
||||
this.sourceLocation = sourceLocation;
|
||||
}
|
||||
|
||||
public T bundleName(String bundleName) {
|
||||
setBundleName(bundleName);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public void setBundleName(String bundleName) {
|
||||
this.bundleName = bundleName;
|
||||
}
|
||||
|
||||
public BundleController bundleController() {
|
||||
return (BundleController) this;
|
||||
}
|
||||
|
||||
protected BundleInstaller createBundleInstaller() {
|
||||
return typed(BundleInstaller.class);
|
||||
}
|
||||
|
||||
protected void initBundleInstaller() {
|
||||
if (this.bundleInstaller == null)
|
||||
this.bundleInstaller = createBundleInstaller();
|
||||
}
|
||||
|
||||
protected void clear() {
|
||||
this.artifact = null;
|
||||
this.sourceLocation = null;
|
||||
this.bundleName = null;
|
||||
}
|
||||
|
||||
/*
|
||||
* BundleController implementation
|
||||
*/
|
||||
|
||||
public String installAndStartBundle(String bundleUrl, String bundleName) throws Exception {
|
||||
initBundleInstaller();
|
||||
clear();
|
||||
this.sourceLocation(bundleUrl);
|
||||
refreshTypedInstaller();
|
||||
InstallationResult result = this.bundleInstaller.update(bundleName).installOnlyIfMissing().start().install();
|
||||
return result.getProperties()
|
||||
.getOrDefault(InstallationResult.PROP_BUNDLE_STATUS, "RESOLVED")
|
||||
.toString();
|
||||
initBundleInstaller();
|
||||
clear();
|
||||
this.sourceLocation(bundleUrl);
|
||||
refreshTypedInstaller();
|
||||
InstallationResult result = this.bundleInstaller.update(bundleName).installOnlyIfMissing().start().install();
|
||||
return result.getProperties()
|
||||
.getOrDefault(InstallationResult.PROP_BUNDLE_STATUS, "RESOLVED")
|
||||
.toString();
|
||||
};
|
||||
|
||||
public void installBundle(String bundleUrl) throws Exception {
|
||||
initBundleInstaller();
|
||||
clear();
|
||||
this.sourceLocation(bundleUrl);
|
||||
refreshTypedInstaller();
|
||||
this.bundleInstaller.update().installOnlyIfMissing().install();
|
||||
initBundleInstaller();
|
||||
clear();
|
||||
this.sourceLocation(bundleUrl);
|
||||
refreshTypedInstaller();
|
||||
this.bundleInstaller.update().installOnlyIfMissing().install();
|
||||
};
|
||||
|
||||
|
||||
public String updateBundle(String bundleName) throws Exception {
|
||||
initBundleInstaller();
|
||||
clear();
|
||||
InstallationResult result = this.bundleInstaller.update(bundleName).updateOnly().install();
|
||||
return result.getProperties()
|
||||
.getOrDefault(InstallationResult.PROP_BUNDLE_STATUS, "Resolved")
|
||||
.toString();
|
||||
initBundleInstaller();
|
||||
clear();
|
||||
InstallationResult result = this.bundleInstaller.update(bundleName).updateOnly().install();
|
||||
return result.getProperties()
|
||||
.getOrDefault(InstallationResult.PROP_BUNDLE_STATUS, "Resolved")
|
||||
.toString();
|
||||
};
|
||||
|
||||
public String startBundle(String bundleName) throws Exception {
|
||||
initBundleInstaller();
|
||||
clear();
|
||||
bundleName(bundleName);
|
||||
refreshTypedInstaller();
|
||||
InstallationResult result = this.bundleInstaller.startOnly().install();
|
||||
return result.getProperties().getOrDefault(InstallationResult.PROP_BUNDLE_STATUS
|
||||
, "Resolved").toString();
|
||||
initBundleInstaller();
|
||||
clear();
|
||||
bundleName(bundleName);
|
||||
refreshTypedInstaller();
|
||||
InstallationResult result = this.bundleInstaller.startOnly().install();
|
||||
return result.getProperties().getOrDefault(InstallationResult.PROP_BUNDLE_STATUS, "Resolved").toString();
|
||||
};
|
||||
|
||||
public String stopBundle(String bundleName) throws Exception {
|
||||
initBundleInstaller();
|
||||
clear();
|
||||
bundleName(bundleName);
|
||||
refreshTypedInstaller();
|
||||
InstallationResult result = this.bundleInstaller.stopOnly().install();
|
||||
return result.getProperties().getOrDefault(InstallationResult.PROP_BUNDLE_STATUS
|
||||
, "Resolved").toString();
|
||||
initBundleInstaller();
|
||||
clear();
|
||||
bundleName(bundleName);
|
||||
refreshTypedInstaller();
|
||||
InstallationResult result = this.bundleInstaller.stopOnly().install();
|
||||
return result.getProperties().getOrDefault(InstallationResult.PROP_BUNDLE_STATUS, "Resolved").toString();
|
||||
};
|
||||
|
||||
public void uninstallBundle(String bundleName) throws Exception {
|
||||
initBundleInstaller();
|
||||
clear();
|
||||
bundleName(bundleName);
|
||||
refreshTypedInstaller();
|
||||
this.bundleInstaller.uninstall();
|
||||
};
|
||||
|
||||
initBundleInstaller();
|
||||
clear();
|
||||
bundleName(bundleName);
|
||||
refreshTypedInstaller();
|
||||
this.bundleInstaller.uninstall();
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -39,7 +39,8 @@ import org.apache.karaf.cellar.bundle.BundleState;
|
||||
import org.apache.karaf.cellar.bundle.management.CellarBundleMBean;
|
||||
import org.apache.karaf.cellar.core.ClusterManager;
|
||||
import org.apache.karaf.cellar.core.Configurations;
|
||||
import org.osgi.framework.Constants;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ru.entaxy.esb.system.common.exception.BundleNotFound;
|
||||
import ru.entaxy.platform.base.support.CommonUtils;
|
||||
@ -50,243 +51,254 @@ import ru.entaxy.platform.core.artifact.installer.builder.typed.impl.CommonBundl
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.typed.impl.CommonBundleInstallerHelperConfig;
|
||||
|
||||
public class ClusterCommonBundleInstallerHelper extends ClusterTypedInstallerHelper
|
||||
implements CommonBundleInstallerHelper {
|
||||
implements CommonBundleInstallerHelper {
|
||||
|
||||
protected CommonBundleInstallerHelperConfig config;
|
||||
|
||||
protected ClassLoader backup;
|
||||
|
||||
@Override
|
||||
public void setConfig(CommonBundleInstallerHelperConfig config) {
|
||||
this.config = config;
|
||||
}
|
||||
private static final Logger log = LoggerFactory.getLogger(ClusterCommonBundleInstallerHelper.class);
|
||||
|
||||
protected void replaceClassLoader() {
|
||||
this.backup = Thread.currentThread().getContextClassLoader();
|
||||
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
|
||||
}
|
||||
|
||||
protected void restoreClassLoader() {
|
||||
if (this.backup != null) {
|
||||
Thread.currentThread().setContextClassLoader(this.backup);
|
||||
this.backup = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstallationResultImpl install(InstallationResultImpl installationResult) {
|
||||
//ClusterTypedInstallerHelper _helper = (ClusterTypedInstallerHelper)helper;
|
||||
|
||||
// InstallationResultImpl installationResult = InstallationResultImpl
|
||||
// .create()
|
||||
// .property("artifact", artifact);
|
||||
protected CommonBundleInstallerHelperConfig config;
|
||||
|
||||
CompositeData existingBundle = null;
|
||||
|
||||
List<String> groupsToInstall = new ArrayList<>();
|
||||
for (String groupName: getGroups())
|
||||
if (checkGroup(groupName))
|
||||
if (!groupsToInstall.contains(groupName))
|
||||
groupsToInstall.add(groupName);
|
||||
|
||||
if (groupsToInstall.size()==0) {
|
||||
return installationResult.failed("No groups to install to");
|
||||
}
|
||||
|
||||
replaceClassLoader();
|
||||
|
||||
CellarBundleMBean bundleService = OSGIUtils.getService(CellarBundleMBean.class);
|
||||
protected ClassLoader backup;
|
||||
|
||||
ClusterManager clusterManager = OSGIUtils.getService(ClusterManager.class);
|
||||
|
||||
if ((bundleService == null) || (clusterManager == null)) {
|
||||
// TODO throw exception
|
||||
return installationResult
|
||||
.failed("Can't install/update: CellarBundleMBean or ClusterManager not available");
|
||||
}
|
||||
@Override
|
||||
public void setConfig(CommonBundleInstallerHelperConfig config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
// TODO decide if we really need several groups
|
||||
// now we use only the first one
|
||||
String groupToInstall = groupsToInstall.get(0);
|
||||
|
||||
if (this.config.isUpdate() || this.config.isUpdateOnly() || this.config.isInstallOnlyIfMissing()
|
||||
|| this.config.isStartBundleOnly() || this.config.isStopBundleOnly()) {
|
||||
|
||||
|
||||
String bundleId = this.config.getBundleId();
|
||||
|
||||
if (!CommonUtils.isValid(bundleId)) {
|
||||
// TODO throw exception
|
||||
return installationResult
|
||||
.failed("Can't update: bundleId can not be defined");
|
||||
}
|
||||
|
||||
// if not bundles found BundleService throws exception
|
||||
try {
|
||||
existingBundle = getBundleData(bundleId, bundleService, groupToInstall);
|
||||
} catch (Exception e) {
|
||||
// NOOP
|
||||
}
|
||||
|
||||
Map<String, List<BundleState>> foundBundlesMap = new HashMap<>();
|
||||
|
||||
for (String s: groupsToInstall) {
|
||||
Map<String, BundleState> clusterBundles = clusterManager.getMap(org.apache.karaf.cellar.bundle.Constants.BUNDLE_MAP
|
||||
+ Configurations.SEPARATOR
|
||||
+ s);
|
||||
List<BundleState> foundClusterBundles = clusterBundles.values().stream()
|
||||
.filter(b -> b.getSymbolicName().equals(bundleId))
|
||||
.collect(Collectors.toList());
|
||||
if (foundClusterBundles.size() > 0)
|
||||
foundBundlesMap.put(s, foundClusterBundles);
|
||||
}
|
||||
|
||||
if ((existingBundle != null) && foundBundlesMap.isEmpty()) {
|
||||
// bundle is only installed locally but expected to be in cluster
|
||||
restoreClassLoader();
|
||||
return installationResult.failed("Bundle ["
|
||||
.concat(bundleId).concat("]" )
|
||||
.concat(" is installed locally only; cluster state must be restored"));
|
||||
}
|
||||
|
||||
if (existingBundle != null) {
|
||||
|
||||
installationResult.object(existingBundle);
|
||||
protected void replaceClassLoader() {
|
||||
this.backup = Thread.currentThread().getContextClassLoader();
|
||||
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
|
||||
}
|
||||
|
||||
if (this.config.isInstallOnlyIfMissing()) {
|
||||
|
||||
installationResult.notChanged();
|
||||
|
||||
} else
|
||||
protected void restoreClassLoader() {
|
||||
if (this.backup != null) {
|
||||
Thread.currentThread().setContextClassLoader(this.backup);
|
||||
this.backup = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.config.isUpdate() || this.config.isUpdateOnly()) {
|
||||
|
||||
try {
|
||||
if (this.config.isStartBundle())
|
||||
bundleService.updateStart(groupToInstall, bundleId, this.config.getBundleLocation());
|
||||
else
|
||||
bundleService.update(groupToInstall, bundleId, this.config.getBundleLocation());
|
||||
|
||||
installationResult.updated();
|
||||
} catch (Exception e) {
|
||||
installationResult.failed().error(e);
|
||||
}
|
||||
} else
|
||||
|
||||
if (this.config.isStartBundleOnly()) {
|
||||
|
||||
try {
|
||||
bundleService.start(groupToInstall, bundleId);
|
||||
installationResult.started()
|
||||
.property(InstallationResult.PROP_BUNDLE_STATUS
|
||||
, getStatusByName(bundleId, bundleService, groupToInstall));
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
installationResult.failed().error(e);
|
||||
}
|
||||
|
||||
} else
|
||||
|
||||
if (this.config.isStopBundleOnly()) {
|
||||
@Override
|
||||
public InstallationResultImpl install(InstallationResultImpl installationResult) {
|
||||
// ClusterTypedInstallerHelper _helper = (ClusterTypedInstallerHelper)helper;
|
||||
|
||||
try {
|
||||
bundleService.stop(groupToInstall, bundleId);
|
||||
installationResult.stopped()
|
||||
.property(InstallationResult.PROP_BUNDLE_STATUS
|
||||
, getStatusByName(bundleId, bundleService, groupToInstall));
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
installationResult.failed().error(e);
|
||||
}
|
||||
// InstallationResultImpl installationResult = InstallationResultImpl
|
||||
// .create()
|
||||
// .property("artifact", artifact);
|
||||
|
||||
}
|
||||
|
||||
restoreClassLoader();
|
||||
|
||||
return installationResult;
|
||||
}
|
||||
}
|
||||
CompositeData existingBundle = null;
|
||||
|
||||
if (this.config.isUpdateOnly()) {
|
||||
return installationResult.failed("UpdateOnly failed: bundle to update not found");
|
||||
}
|
||||
|
||||
try {
|
||||
if (this.config.getStartLevel() > 0) {
|
||||
bundleService.install(groupToInstall, this.config.getBundleLocation()
|
||||
, this.config.getStartLevel(), this.config.isStartBundle());
|
||||
} else {
|
||||
bundleService.install(groupToInstall, this.config.getBundleLocation(), this.config.isStartBundle());
|
||||
}
|
||||
installationResult.installed()
|
||||
.property(InstallationResult.PROP_BUNDLE_STATUS
|
||||
, getStatusByLocation(this.config.getBundleLocation(), bundleService, groupToInstall));
|
||||
} catch (Exception e) {
|
||||
installationResult.error(e)
|
||||
.failed("Installing bundle failed: Exception");
|
||||
}
|
||||
|
||||
replaceClassLoader();
|
||||
|
||||
return installationResult.installed();
|
||||
}
|
||||
List<String> groupsToInstall = new ArrayList<>();
|
||||
for (String groupName : getGroups())
|
||||
if (checkGroup(groupName))
|
||||
if (!groupsToInstall.contains(groupName))
|
||||
groupsToInstall.add(groupName);
|
||||
|
||||
@Override
|
||||
public InstallationResultImpl uninstall(InstallationResultImpl installationResult) {
|
||||
CompositeData existingBundle = null;
|
||||
|
||||
List<String> groupsToInstall = new ArrayList<>();
|
||||
for (String groupName: getGroups())
|
||||
if (checkGroup(groupName))
|
||||
if (!groupsToInstall.contains(groupName))
|
||||
groupsToInstall.add(groupName);
|
||||
|
||||
if (groupsToInstall.size()==0) {
|
||||
return installationResult.failed("No groups to install to");
|
||||
}
|
||||
|
||||
CellarBundleMBean bundleService = OSGIUtils.getService(CellarBundleMBean.class);
|
||||
if (groupsToInstall.size() == 0) {
|
||||
return installationResult.failed("No groups to install to");
|
||||
}
|
||||
|
||||
if (bundleService == null) {
|
||||
// TODO throw exception
|
||||
return installationResult
|
||||
.failed("Can't install/update: CellarBundleMBean not available");
|
||||
}
|
||||
replaceClassLoader();
|
||||
|
||||
// TODO decide if we really need several groups
|
||||
// now we use only the first one
|
||||
String groupToInstall = groupsToInstall.get(0);
|
||||
String bundleId = this.config.getBundleId();
|
||||
|
||||
if (!CommonUtils.isValid(bundleId)) {
|
||||
// TODO throw exception
|
||||
return installationResult
|
||||
.failed("Can't update: bundleId can not be defined");
|
||||
}
|
||||
|
||||
// if not bundles found BundleService throws exception
|
||||
try {
|
||||
existingBundle = getBundleData(bundleId, bundleService, groupToInstall);
|
||||
} catch (Exception e) {
|
||||
// NOOP
|
||||
}
|
||||
|
||||
if (existingBundle != null) {
|
||||
try {
|
||||
bundleService.uninstall(groupToInstall, bundleId);
|
||||
installationResult.uninstalled();
|
||||
} catch (Exception e) {
|
||||
installationResult.failed("Failed uninstalling bundle [" + bundleId + "]").error(e);
|
||||
}
|
||||
} else {
|
||||
installationResult.notChanged().message("BUNDLE NOT FOUND");
|
||||
}
|
||||
return installationResult;
|
||||
}
|
||||
|
||||
private String getStatusByLocation(String bundleLocation
|
||||
, CellarBundleMBean cellarBundleMBean
|
||||
, String cellarGroup) throws Exception {
|
||||
CellarBundleMBean bundleService = null;
|
||||
ClusterManager clusterManager = null;
|
||||
try {
|
||||
bundleService = OSGIUtils.services().ofClass(CellarBundleMBean.class).waitService(20000).get();
|
||||
clusterManager = OSGIUtils.services().ofClass(ClusterManager.class).waitService(20000).get();
|
||||
} catch (Exception e) {
|
||||
log.trace(e.getMessage());
|
||||
}
|
||||
|
||||
if ((bundleService == null) || (clusterManager == null)) {
|
||||
// TODO throw exception
|
||||
return installationResult
|
||||
.failed("Can't install/update: CellarBundleMBean or ClusterManager not available");
|
||||
}
|
||||
|
||||
// TODO decide if we really need several groups
|
||||
// now we use only the first one
|
||||
String groupToInstall = groupsToInstall.get(0);
|
||||
|
||||
if (this.config.isUpdate() || this.config.isUpdateOnly() || this.config.isInstallOnlyIfMissing()
|
||||
|| this.config.isStartBundleOnly() || this.config.isStopBundleOnly()) {
|
||||
|
||||
|
||||
String bundleId = this.config.getBundleId();
|
||||
|
||||
if (!CommonUtils.isValid(bundleId)) {
|
||||
// TODO throw exception
|
||||
return installationResult
|
||||
.failed("Can't update: bundleId can not be defined");
|
||||
}
|
||||
|
||||
// if not bundles found BundleService throws exception
|
||||
try {
|
||||
existingBundle = getBundleData(bundleId, bundleService, groupToInstall);
|
||||
} catch (Exception e) {
|
||||
// NOOP
|
||||
}
|
||||
|
||||
Map<String, List<BundleState>> foundBundlesMap = new HashMap<>();
|
||||
|
||||
for (String s : groupsToInstall) {
|
||||
Map<String, BundleState> clusterBundles =
|
||||
clusterManager.getMap(org.apache.karaf.cellar.bundle.Constants.BUNDLE_MAP
|
||||
+ Configurations.SEPARATOR
|
||||
+ s);
|
||||
List<BundleState> foundClusterBundles = clusterBundles.values().stream()
|
||||
.filter(b -> b.getSymbolicName().equals(bundleId))
|
||||
.collect(Collectors.toList());
|
||||
if (foundClusterBundles.size() > 0)
|
||||
foundBundlesMap.put(s, foundClusterBundles);
|
||||
}
|
||||
|
||||
if ((existingBundle != null) && foundBundlesMap.isEmpty()) {
|
||||
if (this.config.isForceInstall()) {
|
||||
log.warn("Bundle [{}] is found locally only but cluster installation is forced", bundleId);
|
||||
} else {
|
||||
// bundle is only installed locally but expected to be in cluster
|
||||
restoreClassLoader();
|
||||
return installationResult.failed("Bundle ["
|
||||
.concat(bundleId).concat("]")
|
||||
.concat(" is installed locally only; cluster state must be restored"));
|
||||
}
|
||||
}
|
||||
|
||||
if (existingBundle != null && !foundBundlesMap.isEmpty()) {
|
||||
|
||||
installationResult.object(existingBundle);
|
||||
|
||||
if (this.config.isInstallOnlyIfMissing()) {
|
||||
|
||||
installationResult.notChanged();
|
||||
|
||||
} else
|
||||
|
||||
if (this.config.isUpdate() || this.config.isUpdateOnly()) {
|
||||
|
||||
try {
|
||||
if (this.config.isStartBundle())
|
||||
bundleService.updateStart(groupToInstall, bundleId, this.config.getBundleLocation());
|
||||
else
|
||||
bundleService.update(groupToInstall, bundleId, this.config.getBundleLocation());
|
||||
|
||||
installationResult.updated();
|
||||
} catch (Exception e) {
|
||||
installationResult.failed().error(e);
|
||||
}
|
||||
} else
|
||||
|
||||
if (this.config.isStartBundleOnly()) {
|
||||
|
||||
try {
|
||||
bundleService.start(groupToInstall, bundleId);
|
||||
installationResult.started()
|
||||
.property(InstallationResult.PROP_BUNDLE_STATUS,
|
||||
getStatusByName(bundleId, bundleService, groupToInstall));
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
installationResult.failed().error(e);
|
||||
}
|
||||
|
||||
} else
|
||||
|
||||
if (this.config.isStopBundleOnly()) {
|
||||
|
||||
try {
|
||||
bundleService.stop(groupToInstall, bundleId);
|
||||
installationResult.stopped()
|
||||
.property(InstallationResult.PROP_BUNDLE_STATUS,
|
||||
getStatusByName(bundleId, bundleService, groupToInstall));
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
installationResult.failed().error(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
restoreClassLoader();
|
||||
|
||||
return installationResult;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.config.isUpdateOnly()) {
|
||||
return installationResult.failed("UpdateOnly failed: bundle to update not found");
|
||||
}
|
||||
|
||||
try {
|
||||
if (this.config.getStartLevel() > 0) {
|
||||
bundleService.install(groupToInstall, this.config.getBundleLocation(), this.config.getStartLevel(),
|
||||
this.config.isStartBundle());
|
||||
} else {
|
||||
bundleService.install(groupToInstall, this.config.getBundleLocation(), this.config.isStartBundle());
|
||||
}
|
||||
installationResult.installed()
|
||||
.property(InstallationResult.PROP_BUNDLE_STATUS,
|
||||
getStatusByLocation(this.config.getBundleLocation(), bundleService, groupToInstall));
|
||||
} catch (Exception e) {
|
||||
installationResult.error(e)
|
||||
.failed("Installing bundle failed: Exception");
|
||||
}
|
||||
|
||||
replaceClassLoader();
|
||||
|
||||
return installationResult.installed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstallationResultImpl uninstall(InstallationResultImpl installationResult) {
|
||||
CompositeData existingBundle = null;
|
||||
|
||||
List<String> groupsToInstall = new ArrayList<>();
|
||||
for (String groupName : getGroups())
|
||||
if (checkGroup(groupName))
|
||||
if (!groupsToInstall.contains(groupName))
|
||||
groupsToInstall.add(groupName);
|
||||
|
||||
if (groupsToInstall.size() == 0) {
|
||||
return installationResult.failed("No groups to install to");
|
||||
}
|
||||
|
||||
CellarBundleMBean bundleService = OSGIUtils.getService(CellarBundleMBean.class);
|
||||
|
||||
if (bundleService == null) {
|
||||
// TODO throw exception
|
||||
return installationResult
|
||||
.failed("Can't install/update: CellarBundleMBean not available");
|
||||
}
|
||||
|
||||
// TODO decide if we really need several groups
|
||||
// now we use only the first one
|
||||
String groupToInstall = groupsToInstall.get(0);
|
||||
String bundleId = this.config.getBundleId();
|
||||
|
||||
if (!CommonUtils.isValid(bundleId)) {
|
||||
// TODO throw exception
|
||||
return installationResult
|
||||
.failed("Can't update: bundleId can not be defined");
|
||||
}
|
||||
|
||||
// if not bundles found BundleService throws exception
|
||||
try {
|
||||
existingBundle = getBundleData(bundleId, bundleService, groupToInstall);
|
||||
} catch (Exception e) {
|
||||
// NOOP
|
||||
}
|
||||
|
||||
if (existingBundle != null) {
|
||||
try {
|
||||
bundleService.uninstall(groupToInstall, bundleId);
|
||||
installationResult.uninstalled();
|
||||
} catch (Exception e) {
|
||||
installationResult.failed("Failed uninstalling bundle [" + bundleId + "]").error(e);
|
||||
}
|
||||
} else {
|
||||
installationResult.notChanged().message("BUNDLE NOT FOUND");
|
||||
}
|
||||
return installationResult;
|
||||
}
|
||||
|
||||
private String getStatusByLocation(String bundleLocation, CellarBundleMBean cellarBundleMBean, String cellarGroup)
|
||||
throws Exception {
|
||||
TabularData tabularData = cellarBundleMBean.getBundles(cellarGroup);
|
||||
String status = null;
|
||||
for (Object value : tabularData.values()) {
|
||||
@ -301,41 +313,39 @@ public class ClusterCommonBundleInstallerHelper extends ClusterTypedInstallerHel
|
||||
return status.toUpperCase();
|
||||
}
|
||||
|
||||
private String getStatusByName(String bundleName
|
||||
, CellarBundleMBean cellarBundleMBean
|
||||
, String cellarGroup) throws Exception {
|
||||
|
||||
CompositeData data = getBundleData(bundleName, cellarBundleMBean, cellarGroup);
|
||||
if ( (data != null) && (data.containsKey("status"))) {
|
||||
Object obj = data.get("status");
|
||||
return obj == null?null:obj.toString();
|
||||
};
|
||||
return null;
|
||||
private String getStatusByName(String bundleName, CellarBundleMBean cellarBundleMBean, String cellarGroup)
|
||||
throws Exception {
|
||||
|
||||
CompositeData data = getBundleData(bundleName, cellarBundleMBean, cellarGroup);
|
||||
if ((data != null) && (data.containsKey("status"))) {
|
||||
Object obj = data.get("status");
|
||||
return obj == null ? null : obj.toString();
|
||||
} ;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private List<CompositeData> getBundlesData(String symbolicName
|
||||
, CellarBundleMBean cellarBundleMBean
|
||||
, String cellarGroup) throws Exception {
|
||||
|
||||
|
||||
private List<CompositeData> getBundlesData(String symbolicName, CellarBundleMBean cellarBundleMBean,
|
||||
String cellarGroup) throws Exception {
|
||||
TabularData tabularData = cellarBundleMBean.getBundles(cellarGroup);
|
||||
List<CompositeData> results = new LinkedList<>();
|
||||
for (Object value : tabularData.values()) {
|
||||
CompositeData compositeData = (CompositeData) value;
|
||||
if (symbolicName.equals(compositeData.get("name")) || symbolicName.equals(compositeData.get("symbolic_name"))) {
|
||||
if (symbolicName.equals(compositeData.get("name"))
|
||||
|| symbolicName.equals(compositeData.get("symbolic_name"))) {
|
||||
results.add(compositeData);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private CompositeData getBundleData(String symbolicName
|
||||
, CellarBundleMBean cellarBundleMBean
|
||||
, String cellarGroup) throws Exception {
|
||||
List<CompositeData> results = getBundlesData(symbolicName, cellarBundleMBean, cellarGroup);
|
||||
if (results.size()==0)
|
||||
return null;
|
||||
private CompositeData getBundleData(String symbolicName, CellarBundleMBean cellarBundleMBean, String cellarGroup)
|
||||
throws Exception {
|
||||
List<CompositeData> results = getBundlesData(symbolicName, cellarBundleMBean, cellarGroup);
|
||||
if (results.size() == 0)
|
||||
return null;
|
||||
else
|
||||
return results.get(0);
|
||||
}
|
||||
|
||||
return results.get(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -33,9 +33,9 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ru.entaxy.platform.base.support.osgi.OSGIUtils;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.typed.impl.TypedInstallerHelper;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.typed.impl.TypedInstallerHelperImpl;
|
||||
|
||||
public class ClusterTypedInstallerHelper extends TypedInstallerHelper {
|
||||
public class ClusterTypedInstallerHelper extends TypedInstallerHelperImpl {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(ClusterTypedInstallerHelper.class);
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -25,67 +25,82 @@
|
||||
*/
|
||||
package ru.entaxy.platform.core.artifact.installer.builder.impl.cluster;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ru.entaxy.platform.core.artifact.Artifact;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.ClusterInstaller;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.impl.AbstractInstaller;
|
||||
|
||||
public class DefaultCellarInstaller extends AbstractInstaller<ClusterInstaller, ClusterTypedInstallerHelper> implements ClusterInstaller {
|
||||
public class DefaultCellarInstaller extends AbstractInstaller<ClusterInstaller, ClusterTypedInstallerHelper>
|
||||
implements ClusterInstaller {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(DefaultCellarInstaller.class);
|
||||
|
||||
// protected DeployedArtifact artifact = null;
|
||||
|
||||
protected Set<String> groups;
|
||||
|
||||
// TODO read default group name from config
|
||||
protected String defaultGroupName = "default";
|
||||
|
||||
public DefaultCellarInstaller() {
|
||||
|
||||
super();
|
||||
|
||||
/*
|
||||
this.typedInstallerClasses.put(Artifact.ARTIFACT_CATEGORY_BLUEPRINT,
|
||||
ru.entaxy.platform.core.artifact.installer.builder.typed.impl.BlueprintInstallerImpl.class);
|
||||
this.typedInstallerClasses.put(Artifact.ARTIFACT_CATEGORY_BUNDLE,
|
||||
ru.entaxy.platform.core.artifact.installer.builder.typed.impl.BundleInstallerImpl.class);
|
||||
this.typedInstallerClasses.put(Artifact.ARTIFACT_CATEGORY_JAR,
|
||||
ru.entaxy.platform.core.artifact.installer.builder.typed.impl.JarInstallerImpl.class);
|
||||
*/
|
||||
|
||||
this.typedHelperClasses.put(
|
||||
ru.entaxy.platform.core.artifact.installer.builder.typed.BlueprintInstaller.class,
|
||||
ClusterCommonBundleInstallerHelper.class);
|
||||
this.typedHelperClasses.put(
|
||||
ru.entaxy.platform.core.artifact.installer.builder.typed.BundleInstaller.class,
|
||||
ClusterCommonBundleInstallerHelper.class);
|
||||
this.typedHelperClasses.put(
|
||||
ru.entaxy.platform.core.artifact.installer.builder.typed.JarInstaller.class,
|
||||
ClusterCommonBundleInstallerHelper.class);
|
||||
|
||||
initGroups();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<ClusterTypedInstallerHelper> getHelperClass() {
|
||||
return ClusterTypedInstallerHelper.class;
|
||||
}
|
||||
|
||||
protected void initGroups() {
|
||||
groups = new HashSet<>(Arrays.asList(new String[] {this.defaultGroupName}));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ClusterTypedInstallerHelper createDefaultHelper() {
|
||||
return new ClusterTypedInstallerHelper();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initHelper(ClusterTypedInstallerHelper helper) {
|
||||
helper.setGroups(new ArrayList<>(groups));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClusterInstaller groups(String... groups) {
|
||||
if (groups != null && groups.length > 0)
|
||||
this.groups.addAll(Arrays.asList((String[]) groups));
|
||||
else
|
||||
initGroups();
|
||||
return this;
|
||||
}
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(DefaultCellarInstaller.class);
|
||||
|
||||
// protected DeployedArtifact artifact = null;
|
||||
|
||||
protected List<String> groups;
|
||||
|
||||
// TODO read default group name from config
|
||||
protected String defaultGroupName = "default";
|
||||
|
||||
public DefaultCellarInstaller() {
|
||||
|
||||
super();
|
||||
|
||||
this.typedInstallerClasses.put(Artifact.ARTIFACT_CATEGORY_BLUEPRINT, ru.entaxy.platform.core.artifact.installer.builder.typed.impl.BlueprintInstallerImpl.class);
|
||||
this.typedInstallerClasses.put(Artifact.ARTIFACT_CATEGORY_BUNDLE, ru.entaxy.platform.core.artifact.installer.builder.typed.impl.BundleInstallerImpl.class);
|
||||
this.typedInstallerClasses.put(Artifact.ARTIFACT_CATEGORY_JAR, ru.entaxy.platform.core.artifact.installer.builder.typed.impl.JarInstallerImpl.class);
|
||||
|
||||
this.typedHelperClasses.put(ru.entaxy.platform.core.artifact.installer.builder.typed.impl.BlueprintInstallerImpl.class
|
||||
, ClusterCommonBundleInstallerHelper.class);
|
||||
this.typedHelperClasses.put(ru.entaxy.platform.core.artifact.installer.builder.typed.impl.BundleInstallerImpl.class
|
||||
, ClusterCommonBundleInstallerHelper.class);
|
||||
this.typedHelperClasses.put(ru.entaxy.platform.core.artifact.installer.builder.typed.impl.JarInstallerImpl.class
|
||||
, ClusterCommonBundleInstallerHelper.class);
|
||||
|
||||
initGroups();
|
||||
}
|
||||
|
||||
protected void initGroups() {
|
||||
groups = Arrays.asList(new String[] {this.defaultGroupName});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ClusterTypedInstallerHelper createDefaultHelper() {
|
||||
return new ClusterTypedInstallerHelper();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initHelper(ClusterTypedInstallerHelper helper) {
|
||||
helper.setGroups(groups);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClusterInstaller groups(String... groups) {
|
||||
if (groups!=null && groups.length>0)
|
||||
this.groups.addAll(Arrays.asList((String[])groups));
|
||||
else
|
||||
initGroups();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -25,33 +25,38 @@
|
||||
*/
|
||||
package ru.entaxy.platform.core.artifact.installer.builder.impl.local;
|
||||
|
||||
import ru.entaxy.platform.core.artifact.Artifact;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.LocalInstaller;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.impl.AbstractInstaller;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.typed.impl.BlueprintInstallerImpl;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.typed.impl.BundleInstallerImpl;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.typed.impl.JarInstallerImpl;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.typed.BlueprintInstaller;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.typed.BundleInstaller;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.typed.JarInstaller;
|
||||
|
||||
public class DefaultLocalInstaller extends AbstractInstaller<LocalInstaller, LocalTypedInstallerHelper>
|
||||
implements LocalInstaller {
|
||||
public class DefaultLocalInstaller extends AbstractInstaller<LocalInstaller, LocalTypedInstallerHelper>
|
||||
implements LocalInstaller {
|
||||
|
||||
public DefaultLocalInstaller() {
|
||||
|
||||
super();
|
||||
|
||||
this.typedInstallerClasses.put(Artifact.ARTIFACT_CATEGORY_BLUEPRINT, BlueprintInstallerImpl.class);
|
||||
this.typedInstallerClasses.put(Artifact.ARTIFACT_CATEGORY_BUNDLE, BundleInstallerImpl.class);
|
||||
this.typedInstallerClasses.put(Artifact.ARTIFACT_CATEGORY_JAR, JarInstallerImpl.class);
|
||||
|
||||
|
||||
this.typedHelperClasses.put(BlueprintInstallerImpl.class, LocalCommonBundleInstallerHelper.class);
|
||||
this.typedHelperClasses.put(BundleInstallerImpl.class, LocalCommonBundleInstallerHelper.class);
|
||||
this.typedHelperClasses.put(JarInstallerImpl.class, LocalCommonBundleInstallerHelper.class);
|
||||
}
|
||||
public DefaultLocalInstaller() {
|
||||
|
||||
super();
|
||||
|
||||
/*
|
||||
this.typedInstallerClasses.put(Artifact.ARTIFACT_CATEGORY_BLUEPRINT, BlueprintInstallerImpl.class);
|
||||
this.typedInstallerClasses.put(Artifact.ARTIFACT_CATEGORY_BUNDLE, BundleInstallerImpl.class);
|
||||
this.typedInstallerClasses.put(Artifact.ARTIFACT_CATEGORY_JAR, JarInstallerImpl.class);
|
||||
*/
|
||||
|
||||
this.typedHelperClasses.put(BlueprintInstaller.class, LocalCommonBundleInstallerHelper.class);
|
||||
this.typedHelperClasses.put(BundleInstaller.class, LocalCommonBundleInstallerHelper.class);
|
||||
this.typedHelperClasses.put(JarInstaller.class, LocalCommonBundleInstallerHelper.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<LocalTypedInstallerHelper> getHelperClass() {
|
||||
return LocalTypedInstallerHelper.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LocalTypedInstallerHelper createDefaultHelper() {
|
||||
return new LocalTypedInstallerHelper();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LocalTypedInstallerHelper createDefaultHelper() {
|
||||
return new LocalTypedInstallerHelper();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -25,8 +25,8 @@
|
||||
*/
|
||||
package ru.entaxy.platform.core.artifact.installer.builder.impl.local;
|
||||
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.typed.impl.TypedInstallerHelper;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.typed.impl.TypedInstallerHelperImpl;
|
||||
|
||||
public class LocalTypedInstallerHelper extends TypedInstallerHelper {
|
||||
public class LocalTypedInstallerHelper extends TypedInstallerHelperImpl {
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -25,16 +25,24 @@
|
||||
*/
|
||||
package ru.entaxy.platform.core.artifact.installer.builder.typed;
|
||||
|
||||
public interface CommonBundleInstaller extends TypedInstaller, StartAware<CommonBundleInstaller>, StopAware<CommonBundleInstaller> {
|
||||
|
||||
public CommonBundleInstaller startLevel(int startLevel);
|
||||
|
||||
public CommonBundleInstaller installOnlyIfMissing();
|
||||
public CommonBundleInstaller update();
|
||||
public CommonBundleInstaller update(String symbolicName);
|
||||
public CommonBundleInstaller update(String symbolicName, String version);
|
||||
public CommonBundleInstaller updateOnly();
|
||||
public CommonBundleInstaller rawUpdate();
|
||||
|
||||
public CommonBundleInstaller refresh();
|
||||
public interface CommonBundleInstaller
|
||||
extends TypedInstaller, StartAware<CommonBundleInstaller>, StopAware<CommonBundleInstaller> {
|
||||
|
||||
public CommonBundleInstaller startLevel(int startLevel);
|
||||
|
||||
public CommonBundleInstaller installOnlyIfMissing();
|
||||
|
||||
public CommonBundleInstaller forceInstall();
|
||||
|
||||
public CommonBundleInstaller update();
|
||||
|
||||
public CommonBundleInstaller update(String symbolicName);
|
||||
|
||||
public CommonBundleInstaller update(String symbolicName, String version);
|
||||
|
||||
public CommonBundleInstaller updateOnly();
|
||||
|
||||
public CommonBundleInstaller rawUpdate();
|
||||
|
||||
public CommonBundleInstaller refresh();
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -25,8 +25,23 @@
|
||||
*/
|
||||
package ru.entaxy.platform.core.artifact.installer.builder.typed;
|
||||
|
||||
import ru.entaxy.platform.core.artifact.DeployedArtifact;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.CommonInstaller;
|
||||
|
||||
public interface TypedInstaller extends CommonInstaller {
|
||||
|
||||
void clearInstaller();
|
||||
|
||||
void setSourceLocation(String sourceLocation);
|
||||
|
||||
String getSourceLocation();
|
||||
|
||||
void setArtifact(DeployedArtifact artifact);
|
||||
|
||||
DeployedArtifact getArtifact();
|
||||
|
||||
String getTypedName();
|
||||
|
||||
void setTypedName(String typedName);
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -27,32 +27,34 @@ package ru.entaxy.platform.core.artifact.installer.builder.typed.impl;
|
||||
|
||||
public interface CommonBundleInstallerHelperConfig {
|
||||
|
||||
boolean isInstallOnlyIfMissing();
|
||||
boolean isInstallOnlyIfMissing();
|
||||
|
||||
String getBundleLocation();
|
||||
boolean isForceInstall();
|
||||
|
||||
boolean isRawUpdate();
|
||||
String getBundleLocation();
|
||||
|
||||
boolean isRefresh();
|
||||
boolean isRawUpdate();
|
||||
|
||||
boolean isUpdateOnly();
|
||||
boolean isRefresh();
|
||||
|
||||
String getVersion();
|
||||
boolean isUpdateOnly();
|
||||
|
||||
String getSymbolicNameToUpdate();
|
||||
String getVersion();
|
||||
|
||||
boolean isUpdate();
|
||||
String getSymbolicNameToUpdate();
|
||||
|
||||
int getStartLevel();
|
||||
boolean isUpdate();
|
||||
|
||||
boolean isStartBundle();
|
||||
|
||||
boolean isStartBundleOnly();
|
||||
int getStartLevel();
|
||||
|
||||
boolean isStopBundle();
|
||||
|
||||
boolean isStopBundleOnly();
|
||||
boolean isStartBundle();
|
||||
|
||||
String getBundleId();
|
||||
boolean isStartBundleOnly();
|
||||
|
||||
boolean isStopBundle();
|
||||
|
||||
boolean isStopBundleOnly();
|
||||
|
||||
String getBundleId();
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -32,277 +32,291 @@ import ru.entaxy.platform.core.artifact.installer.builder.InstallationResult;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.impl.InstallationResultImpl;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.typed.CommonBundleInstaller;
|
||||
|
||||
public class CommonBundleInstallerImpl extends TypedInstallerImpl
|
||||
implements CommonBundleInstaller, CommonBundleInstallerHelperConfig {
|
||||
public class CommonBundleInstallerImpl extends TypedInstallerImpl
|
||||
implements CommonBundleInstaller, CommonBundleInstallerHelperConfig {
|
||||
|
||||
protected CommonBundleInstallerHelper bundleInstallerHelper = null;
|
||||
|
||||
protected boolean startBundle = false;
|
||||
|
||||
protected boolean startBundleOnly = false;
|
||||
|
||||
protected boolean stopBundle = false;
|
||||
|
||||
protected boolean stopBundleOnly = false;
|
||||
|
||||
// TODO get it from framework settings
|
||||
protected int startLevel = -1;
|
||||
|
||||
protected boolean update = false;
|
||||
|
||||
protected String symbolicNameToUpdate = null;
|
||||
|
||||
protected String version = null;
|
||||
protected CommonBundleInstallerHelper bundleInstallerHelper = null;
|
||||
|
||||
protected boolean updateOnly = false;
|
||||
|
||||
protected boolean refresh = false;
|
||||
|
||||
protected boolean rawUpdate = false;
|
||||
|
||||
protected boolean installOnlyIfMissing = false;
|
||||
|
||||
@Override
|
||||
public void clearInstaller() {
|
||||
super.clearInstaller();
|
||||
|
||||
startBundle = false;
|
||||
startBundleOnly = false;
|
||||
stopBundle = false;
|
||||
stopBundleOnly = false;
|
||||
startLevel = -1;
|
||||
update = false;
|
||||
symbolicNameToUpdate = null;
|
||||
version = null;
|
||||
updateOnly = false;
|
||||
refresh = false;
|
||||
rawUpdate = false;
|
||||
installOnlyIfMissing = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstallationResult install() {
|
||||
InstallationResultImpl result = InstallationResultImpl.create();
|
||||
if (this.bundleInstallerHelper == null)
|
||||
result.failed("HELPER NOT FOUND");
|
||||
else
|
||||
this.bundleInstallerHelper.install(result);
|
||||
return result.property("artifact", this.artifact)
|
||||
.property("bundleId", getBundleId())
|
||||
.property("bundleLocation", getBundleLocation());
|
||||
}
|
||||
protected boolean startBundle = false;
|
||||
|
||||
@Override
|
||||
public InstallationResult uninstall() {
|
||||
InstallationResultImpl result = InstallationResultImpl.create();
|
||||
if (this.bundleInstallerHelper == null)
|
||||
result.failed("HELPER NOT FOUND");
|
||||
else
|
||||
this.bundleInstallerHelper.uninstall(result);
|
||||
return result.property("artifact", this.artifact)
|
||||
.property("bundleId", getBundleId())
|
||||
.property("bundleLocation", getBundleLocation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHelper(TypedInstallerHelper helper) {
|
||||
super.setHelper(helper);
|
||||
if (this.helper instanceof CommonBundleInstallerHelper) {
|
||||
this.bundleInstallerHelper = (CommonBundleInstallerHelper)helper;
|
||||
this.bundleInstallerHelper.setConfig(this);
|
||||
}
|
||||
}
|
||||
|
||||
protected String getArtifactLocation() {
|
||||
return this.artifact.getLocation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonBundleInstaller start() {
|
||||
this.stop(false);
|
||||
this.stopBundleOnly = false;
|
||||
return this.start(true);
|
||||
}
|
||||
protected boolean startBundleOnly = false;
|
||||
|
||||
@Override
|
||||
public CommonBundleInstaller startOnly() {
|
||||
this.start();
|
||||
this.startBundleOnly = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonBundleInstaller start(boolean value) {
|
||||
this.startBundle = value;
|
||||
return this;
|
||||
}
|
||||
protected boolean stopBundle = false;
|
||||
|
||||
@Override
|
||||
public CommonBundleInstaller stop() {
|
||||
this.start(false);
|
||||
this.startBundleOnly = false;
|
||||
return this.stop(true);
|
||||
}
|
||||
protected boolean stopBundleOnly = false;
|
||||
|
||||
@Override
|
||||
public CommonBundleInstaller stopOnly() {
|
||||
this.stop();
|
||||
this.stopBundleOnly = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonBundleInstaller stop(boolean value) {
|
||||
this.stopBundle = value;
|
||||
return this;
|
||||
}
|
||||
// TODO get it from framework settings
|
||||
protected int startLevel = -1;
|
||||
|
||||
@Override
|
||||
public CommonBundleInstaller startLevel(int startLevel) {
|
||||
if (startLevel > 0)
|
||||
this.startLevel = startLevel;
|
||||
return this;
|
||||
}
|
||||
protected boolean update = false;
|
||||
|
||||
@Override
|
||||
public CommonBundleInstaller installOnlyIfMissing() {
|
||||
this.installOnlyIfMissing = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonBundleInstaller update() {
|
||||
return update(null, null);
|
||||
}
|
||||
protected String symbolicNameToUpdate = null;
|
||||
|
||||
@Override
|
||||
public CommonBundleInstaller update(String symbolicName) {
|
||||
return update(symbolicName, null);
|
||||
}
|
||||
protected String version = null;
|
||||
|
||||
@Override
|
||||
public CommonBundleInstaller update(String symbolicName, String version) {
|
||||
this.symbolicNameToUpdate = symbolicName;
|
||||
this.version = version;
|
||||
this.update = true;
|
||||
return this;
|
||||
}
|
||||
protected boolean updateOnly = false;
|
||||
|
||||
@Override
|
||||
public CommonBundleInstaller updateOnly() {
|
||||
this.updateOnly = true;
|
||||
return this;
|
||||
}
|
||||
protected boolean refresh = false;
|
||||
|
||||
@Override
|
||||
public CommonBundleInstaller refresh() {
|
||||
this.refresh = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonBundleInstaller rawUpdate() {
|
||||
this.rawUpdate = true;
|
||||
this.update = true;
|
||||
return this;
|
||||
}
|
||||
protected boolean rawUpdate = false;
|
||||
|
||||
|
||||
/*
|
||||
* CommonBundleInstallerHelperConfig implementation
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean isInstallOnlyIfMissing() {
|
||||
return installOnlyIfMissing;
|
||||
}
|
||||
protected boolean installOnlyIfMissing = false;
|
||||
|
||||
@Override
|
||||
public boolean isStartBundle() {
|
||||
return startBundle;
|
||||
}
|
||||
protected boolean forceInstall = false;
|
||||
|
||||
@Override
|
||||
public boolean isStartBundleOnly() {
|
||||
return startBundleOnly;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStopBundle() {
|
||||
return stopBundle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStopBundleOnly() {
|
||||
return stopBundleOnly;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStartLevel() {
|
||||
return startLevel;
|
||||
}
|
||||
@Override
|
||||
public void clearInstaller() {
|
||||
super.clearInstaller();
|
||||
|
||||
@Override
|
||||
public boolean isUpdate() {
|
||||
return update;
|
||||
}
|
||||
startBundle = false;
|
||||
startBundleOnly = false;
|
||||
stopBundle = false;
|
||||
stopBundleOnly = false;
|
||||
startLevel = -1;
|
||||
update = false;
|
||||
symbolicNameToUpdate = null;
|
||||
version = null;
|
||||
updateOnly = false;
|
||||
refresh = false;
|
||||
rawUpdate = false;
|
||||
installOnlyIfMissing = false;
|
||||
forceInstall = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSymbolicNameToUpdate() {
|
||||
return symbolicNameToUpdate;
|
||||
}
|
||||
@Override
|
||||
public InstallationResult install() {
|
||||
InstallationResultImpl result = InstallationResultImpl.create();
|
||||
if (this.bundleInstallerHelper == null)
|
||||
result.failed("HELPER NOT FOUND");
|
||||
else
|
||||
this.bundleInstallerHelper.install(result);
|
||||
return result.property("artifact", this.artifact)
|
||||
.property("bundleId", getBundleId())
|
||||
.property("bundleLocation", getBundleLocation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
@Override
|
||||
public InstallationResult uninstall() {
|
||||
InstallationResultImpl result = InstallationResultImpl.create();
|
||||
if (this.bundleInstallerHelper == null)
|
||||
result.failed("HELPER NOT FOUND");
|
||||
else
|
||||
this.bundleInstallerHelper.uninstall(result);
|
||||
return result.property("artifact", this.artifact)
|
||||
.property("bundleId", getBundleId())
|
||||
.property("bundleLocation", getBundleLocation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUpdateOnly() {
|
||||
return updateOnly;
|
||||
}
|
||||
@Override
|
||||
public void setHelper(TypedInstallerHelperImpl helper) {
|
||||
super.setHelper(helper);
|
||||
if (this.helper instanceof CommonBundleInstallerHelper) {
|
||||
this.bundleInstallerHelper = (CommonBundleInstallerHelper) helper;
|
||||
this.bundleInstallerHelper.setConfig(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRefresh() {
|
||||
return refresh;
|
||||
}
|
||||
protected String getArtifactLocation() {
|
||||
return this.artifact.getLocation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRawUpdate() {
|
||||
return rawUpdate;
|
||||
}
|
||||
@Override
|
||||
public CommonBundleInstaller start() {
|
||||
this.stop(false);
|
||||
this.stopBundleOnly = false;
|
||||
return this.start(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBundleLocation() {
|
||||
if (CommonUtils.isValid(sourceLocation))
|
||||
return sourceLocation;
|
||||
if (artifact != null)
|
||||
return getArtifactLocation();
|
||||
// TODO throw exception due to misconfiguration
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBundleId() {
|
||||
String bundleId = "";
|
||||
if (CommonUtils.isValid(bundleName)) {
|
||||
bundleId += bundleName;
|
||||
} else if (CommonUtils.isValid(symbolicNameToUpdate)) {
|
||||
bundleId += symbolicNameToUpdate;
|
||||
if (CommonUtils.isValid(version))
|
||||
bundleId += version;
|
||||
} else {
|
||||
if (artifact != null) {
|
||||
Object tmp = artifact.getArtifact().getProperties().get(Constants.BUNDLE_SYMBOLICNAME);
|
||||
if (tmp != null)
|
||||
if (CommonUtils.isValid(tmp.toString()))
|
||||
bundleId += tmp.toString();
|
||||
}
|
||||
}
|
||||
if (!CommonUtils.isValid(bundleId) && (artifact != null)) {
|
||||
bundleId += artifact.getArtifact().getCoordinates().getGroupId()
|
||||
+ "." + artifact.getArtifact().getCoordinates().getArtifactId();
|
||||
}
|
||||
return bundleId;
|
||||
}
|
||||
@Override
|
||||
public CommonBundleInstaller startOnly() {
|
||||
this.start();
|
||||
this.startBundleOnly = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonBundleInstaller start(boolean value) {
|
||||
this.startBundle = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonBundleInstaller stop() {
|
||||
this.start(false);
|
||||
this.startBundleOnly = false;
|
||||
return this.stop(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonBundleInstaller stopOnly() {
|
||||
this.stop();
|
||||
this.stopBundleOnly = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonBundleInstaller stop(boolean value) {
|
||||
this.stopBundle = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonBundleInstaller startLevel(int startLevel) {
|
||||
if (startLevel > 0)
|
||||
this.startLevel = startLevel;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonBundleInstaller installOnlyIfMissing() {
|
||||
this.installOnlyIfMissing = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonBundleInstaller forceInstall() {
|
||||
this.forceInstall = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonBundleInstaller update() {
|
||||
return update(null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonBundleInstaller update(String symbolicName) {
|
||||
return update(symbolicName, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonBundleInstaller update(String symbolicName, String version) {
|
||||
this.symbolicNameToUpdate = symbolicName;
|
||||
this.version = version;
|
||||
this.update = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonBundleInstaller updateOnly() {
|
||||
this.updateOnly = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonBundleInstaller refresh() {
|
||||
this.refresh = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonBundleInstaller rawUpdate() {
|
||||
this.rawUpdate = true;
|
||||
this.update = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* CommonBundleInstallerHelperConfig implementation
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean isInstallOnlyIfMissing() {
|
||||
return installOnlyIfMissing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isForceInstall() {
|
||||
return forceInstall;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStartBundle() {
|
||||
return startBundle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStartBundleOnly() {
|
||||
return startBundleOnly;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStopBundle() {
|
||||
return stopBundle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStopBundleOnly() {
|
||||
return stopBundleOnly;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStartLevel() {
|
||||
return startLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUpdate() {
|
||||
return update;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSymbolicNameToUpdate() {
|
||||
return symbolicNameToUpdate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUpdateOnly() {
|
||||
return updateOnly;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRefresh() {
|
||||
return refresh;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRawUpdate() {
|
||||
return rawUpdate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBundleLocation() {
|
||||
if (CommonUtils.isValid(sourceLocation))
|
||||
return sourceLocation;
|
||||
if (artifact != null)
|
||||
return getArtifactLocation();
|
||||
// TODO throw exception due to misconfiguration
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBundleId() {
|
||||
String bundleId = "";
|
||||
if (CommonUtils.isValid(bundleName)) {
|
||||
bundleId += bundleName;
|
||||
} else if (CommonUtils.isValid(symbolicNameToUpdate)) {
|
||||
bundleId += symbolicNameToUpdate;
|
||||
if (CommonUtils.isValid(version))
|
||||
bundleId += version;
|
||||
} else {
|
||||
if (artifact != null) {
|
||||
Object tmp = artifact.getArtifact().getProperties().get(Constants.BUNDLE_SYMBOLICNAME);
|
||||
if (tmp != null)
|
||||
if (CommonUtils.isValid(tmp.toString()))
|
||||
bundleId += tmp.toString();
|
||||
}
|
||||
}
|
||||
if (!CommonUtils.isValid(bundleId) && (artifact != null)) {
|
||||
bundleId += artifact.getArtifact().getCoordinates().getGroupId()
|
||||
+ "." + artifact.getArtifact().getCoordinates().getArtifactId();
|
||||
}
|
||||
return bundleId;
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -1,30 +0,0 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
* rights to the Software and any copies are the property of the Copyright Holder. Unless
|
||||
* it is explicitly allowed the Copyright Holder, the User is prohibited from using the
|
||||
* Software for commercial purposes to provide services to third parties.
|
||||
*
|
||||
* The Copyright Holder hereby declares that the Software is provided on an "AS IS".
|
||||
* Under no circumstances does the Copyright Holder guarantee or promise that the
|
||||
* Software provided by him will be suitable or not suitable for the specific purposes
|
||||
* of the User, that the Software will meet all commercial and personal subjective
|
||||
* expectations of the User, that the Software will work properly, without technical
|
||||
* errors, quickly and uninterruptedly.
|
||||
*
|
||||
* Under no circumstances shall the Copyright Holder or its Affiliates is not liable
|
||||
* to the User for any direct or indirect losses of the User, his expenses or actual
|
||||
* damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
|
||||
* or damage to data, property, etc.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.artifact.installer.builder.typed.impl;
|
||||
|
||||
public class TypedInstallerHelper {
|
||||
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -28,49 +28,68 @@ package ru.entaxy.platform.core.artifact.installer.builder.typed.impl;
|
||||
import ru.entaxy.platform.core.artifact.DeployedArtifact;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.typed.TypedInstaller;
|
||||
|
||||
public abstract class TypedInstallerImpl implements TypedInstaller {
|
||||
public abstract class TypedInstallerImpl implements TypedInstaller, TypedInstallerHelperAware {
|
||||
|
||||
protected TypedInstallerHelper helper;
|
||||
|
||||
protected DeployedArtifact artifact;
|
||||
protected String sourceLocation;
|
||||
protected String bundleName;
|
||||
|
||||
public DeployedArtifact getArtifact() {
|
||||
return artifact;
|
||||
}
|
||||
protected TypedInstallerHelperImpl helper;
|
||||
|
||||
public void setArtifact(DeployedArtifact artifact) {
|
||||
this.artifact = artifact;
|
||||
}
|
||||
protected DeployedArtifact artifact;
|
||||
protected String sourceLocation;
|
||||
protected String bundleName;
|
||||
|
||||
public String getSourceLocation() {
|
||||
return sourceLocation;
|
||||
}
|
||||
@Override
|
||||
public DeployedArtifact getArtifact() {
|
||||
return artifact;
|
||||
}
|
||||
|
||||
public void setSourceLocation(String sourceLocation) {
|
||||
this.sourceLocation = sourceLocation;
|
||||
}
|
||||
@Override
|
||||
public void setArtifact(DeployedArtifact artifact) {
|
||||
this.artifact = artifact;
|
||||
}
|
||||
|
||||
public String getBundleName() {
|
||||
return bundleName;
|
||||
}
|
||||
@Override
|
||||
public String getSourceLocation() {
|
||||
return sourceLocation;
|
||||
}
|
||||
|
||||
public void setBundleName(String bundleName) {
|
||||
this.bundleName = bundleName;
|
||||
}
|
||||
@Override
|
||||
public void setSourceLocation(String sourceLocation) {
|
||||
this.sourceLocation = sourceLocation;
|
||||
}
|
||||
|
||||
public TypedInstallerHelper getHelper() {
|
||||
return helper;
|
||||
}
|
||||
@Override
|
||||
public String getTypedName() {
|
||||
return getBundleName();
|
||||
}
|
||||
|
||||
public void setHelper(TypedInstallerHelper helper) {
|
||||
this.helper = helper;
|
||||
}
|
||||
|
||||
public void clearInstaller() {
|
||||
artifact = null;
|
||||
sourceLocation = null;
|
||||
bundleName = null;
|
||||
}
|
||||
@Deprecated(since = "1.10", forRemoval = true)
|
||||
public String getBundleName() {
|
||||
return bundleName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTypedName(String typedName) {
|
||||
setBundleName(typedName);
|
||||
}
|
||||
|
||||
@Deprecated(since = "1.10", forRemoval = true)
|
||||
public void setBundleName(String bundleName) {
|
||||
this.bundleName = bundleName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedInstallerHelperImpl getHelper() {
|
||||
return helper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHelper(TypedInstallerHelperImpl helper) {
|
||||
this.helper = helper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearInstaller() {
|
||||
artifact = null;
|
||||
sourceLocation = null;
|
||||
bundleName = null;
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* cellar-deployer
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -25,29 +25,35 @@
|
||||
*/
|
||||
package ru.entaxy.platform.core.artifact.repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import ru.entaxy.platform.core.artifact.Artifact;
|
||||
import ru.entaxy.platform.core.artifact.DeployedArtifact;
|
||||
|
||||
public interface ArtifactRepository {
|
||||
|
||||
public static final String REPO_NAME_LOCAL = "entaxy-local";
|
||||
|
||||
public static final String REPO_NAME_SHARED = "entaxy-shared";
|
||||
|
||||
public static final String REPO_NAME_UPDATES = "entaxy-updates";
|
||||
|
||||
public String getName();
|
||||
|
||||
public boolean isHealthy();
|
||||
|
||||
public boolean isEnabled();
|
||||
|
||||
public boolean isReadOnly();
|
||||
|
||||
public boolean isSnapshotsAllowed();
|
||||
|
||||
public String getUrl();
|
||||
|
||||
public DeployedArtifact deploy(Artifact artifact);
|
||||
|
||||
|
||||
public static final String REPO_NAME_LOCAL = "entaxy-local";
|
||||
|
||||
public static final String REPO_NAME_SHARED = "entaxy-shared";
|
||||
|
||||
public static final String REPO_NAME_UPDATES = "entaxy-updates";
|
||||
|
||||
public String getName();
|
||||
|
||||
public boolean isHealthy();
|
||||
|
||||
public boolean isEnabled();
|
||||
|
||||
public boolean isReadOnly();
|
||||
|
||||
public boolean isSnapshotsAllowed();
|
||||
|
||||
public String getUrl();
|
||||
|
||||
public boolean isSystem();
|
||||
|
||||
public DeployedArtifact deploy(Artifact artifact);
|
||||
|
||||
public List<String> getAvailableVersions(Artifact artifact);
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -53,7 +53,10 @@ public class ArtifactRepositoryInitializer extends AbstractInitializer {
|
||||
private static final String PROP_ENTAXY_REPO_LIST = "org.ops4j.pax.url.mvn.repositories.entaxy";
|
||||
|
||||
private static final String ENTAXY_PROPERTY_HTTP_PORT = "entaxy.org.osgi.service.http.port";
|
||||
|
||||
|
||||
private static final String WEB_CONFIG_PID = "org.ops4j.pax.web";
|
||||
private static final String HTTP_ENABLED = "org.osgi.service.http.enabled";
|
||||
|
||||
private ArtifactService artifactService = null;
|
||||
|
||||
protected ConfigRepository configRepository;
|
||||
@ -92,7 +95,7 @@ public class ArtifactRepositoryInitializer extends AbstractInitializer {
|
||||
|
||||
|
||||
List<String> repositoryUrls = new ArrayList<>();
|
||||
String urlPrefix = "http://localhost:${" + ENTAXY_PROPERTY_HTTP_PORT + "}";
|
||||
String urlPrefix = "http" + (isHttpEnabled() ? "" : "s") + "://localhost:${" + ENTAXY_PROPERTY_HTTP_PORT + "}";
|
||||
|
||||
// check if 'local' and 'shared' repositories are defined
|
||||
|
||||
@ -192,4 +195,19 @@ public class ArtifactRepositoryInitializer extends AbstractInitializer {
|
||||
|
||||
}
|
||||
|
||||
protected boolean isHttpEnabled() {
|
||||
boolean httpEnabled = true;
|
||||
try {
|
||||
ConfigRepository configRepository =
|
||||
OSGIUtils.services().ofClass(ConfigRepository.class).waitService(20000).get();
|
||||
|
||||
TypedProperties properties = configRepository.getConfig(WEB_CONFIG_PID);
|
||||
|
||||
httpEnabled = Boolean.parseBoolean(properties.getOrDefault(HTTP_ENABLED, "true").toString());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return httpEnabled;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -29,204 +29,249 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.camel.tooling.model.Strings;
|
||||
import org.apache.karaf.cave.repository.Repository;
|
||||
import org.apache.karaf.cave.repository.RepositoryService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import ru.entaxy.platform.base.support.xml.CommonXMLUtils;
|
||||
import ru.entaxy.platform.core.artifact.Artifact;
|
||||
import ru.entaxy.platform.core.artifact.ArtifactCoordinates;
|
||||
import ru.entaxy.platform.core.artifact.DeployedArtifact;
|
||||
import ru.entaxy.platform.core.artifact.repository.ArtifactRepository;
|
||||
import ru.entaxy.platform.core.artifact.repository.RepositoryDescriptor;
|
||||
import ru.entaxy.platform.core.artifact.repository.impl.remote.RemoteRepository;
|
||||
import ru.entaxy.platform.core.artifact.repository.impl.remote.RemoteRepositoryDescriptor;
|
||||
import ru.entaxy.platform.core.artifact.repository.impl.remote.RemoteRepositoryFactory;
|
||||
|
||||
public class ArtifactRepositoryImpl implements ArtifactRepository {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(ArtifactRepositoryImpl.class);
|
||||
|
||||
protected boolean isHealthy = false;
|
||||
|
||||
protected RepositoryService repositoryService;
|
||||
|
||||
protected RepositoryDescriptor repositoryDescriptor;
|
||||
|
||||
protected RemoteRepository remoteRepository = null;
|
||||
|
||||
public ArtifactRepositoryImpl() {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public ArtifactRepositoryImpl(RepositoryDescriptor descriptor) {
|
||||
this();
|
||||
this.repositoryDescriptor = descriptor;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
Repository caveRepo = repositoryService.repository(repositoryDescriptor.getName());
|
||||
if (caveRepo == null) {
|
||||
caveRepo = createRepo();
|
||||
} else {
|
||||
caveRepo = checkUpdateRepo(caveRepo);
|
||||
}
|
||||
}
|
||||
|
||||
protected Repository createRepo(){
|
||||
Repository repo = null;
|
||||
try {
|
||||
repo = repositoryService.create(
|
||||
repositoryDescriptor.getName(),
|
||||
repositoryDescriptor.getLocation(),
|
||||
Strings.isNullOrEmpty(repositoryDescriptor.getUrl())
|
||||
?"/repositories/" + repositoryDescriptor.getName()
|
||||
:repositoryDescriptor.getUrl(),
|
||||
repositoryDescriptor.isProxy() && !Strings.isNullOrEmpty(repositoryDescriptor.getRemotes())
|
||||
?repositoryDescriptor.getRemotes()
|
||||
:null,
|
||||
/*
|
||||
repositoryDescriptor.isProxy() && !Strings.isNullOrEmpty(repositoryDescriptor.getRemotes())
|
||||
&& !Strings.isNullOrEmpty(repositoryDescriptor.getLocation())
|
||||
?repositoryDescriptor.isMirror()
|
||||
:false*/
|
||||
repositoryDescriptor.isMirror(),
|
||||
"karaf",
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
8);
|
||||
this.isHealthy = true;
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
this.isHealthy = false;
|
||||
}
|
||||
return repo;
|
||||
}
|
||||
|
||||
protected Repository checkUpdateRepo(Repository repo) {
|
||||
try {
|
||||
log.info("repositoryDescriptor.getLocation(): [{}]; repo.getLocation(): [{}]", repositoryDescriptor.getLocation(), repo.getLocation());
|
||||
if (!Strings.isNullOrEmpty(repositoryDescriptor.getLocation())
|
||||
&& !repo.getLocation().equalsIgnoreCase(repositoryDescriptor.getLocation()))
|
||||
repositoryService.changeLocation(repositoryDescriptor.getName(), repositoryDescriptor.getLocation());
|
||||
if (!repo.getUrl().equalsIgnoreCase(repositoryDescriptor.getUrl())
|
||||
&& !Strings.isNullOrEmpty(repositoryDescriptor.getUrl()))
|
||||
repositoryService.changeUrl(repositoryDescriptor.getName(), repositoryDescriptor.getUrl());
|
||||
String repoProxy = repo.getProxy();
|
||||
boolean repoIsProxy = !Strings.isNullOrEmpty(repoProxy);
|
||||
if (repoIsProxy != repositoryDescriptor.isProxy()) {
|
||||
if (!repositoryDescriptor.isProxy)
|
||||
repositoryService.changeProxy(repositoryDescriptor.getName(), "", false);
|
||||
else
|
||||
repositoryService.changeProxy(repositoryDescriptor.getName()
|
||||
, repositoryDescriptor.getRemotes()
|
||||
, repositoryDescriptor.isMirror());
|
||||
}
|
||||
this.isHealthy = true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
this.isHealthy = false;
|
||||
}
|
||||
return repo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeployedArtifact deploy(Artifact artifact) {
|
||||
if (isHealthy() && isEnabled() && !isReadOnly()) {
|
||||
return deployArtifact(artifact);
|
||||
}
|
||||
return new DeployedArtifactImpl(artifact);
|
||||
}
|
||||
private static final Logger log = LoggerFactory.getLogger(ArtifactRepositoryImpl.class);
|
||||
|
||||
protected DeployedArtifact deployArtifact(Artifact artifact) {
|
||||
String location = "mvn:";
|
||||
|
||||
if (!repositoryDescriptor.isProxy() || repositoryDescriptor.isMirror())
|
||||
deployToCave(artifact);
|
||||
|
||||
if (repositoryDescriptor.isProxy())
|
||||
deployToRemoteMaven(artifact);
|
||||
|
||||
return new DeployedArtifactImpl(artifact, location + artifact.getCoordinates().toString());
|
||||
}
|
||||
|
||||
protected void deployToCave(Artifact artifact) {
|
||||
if (artifact.getContent() != null) {
|
||||
try {
|
||||
ArtifactCoordinates coords = artifact.getCoordinates();
|
||||
File tmpFile = File.createTempFile(getName()+"-", Calendar.getInstance().getTimeInMillis()+"");
|
||||
artifact.toFile(tmpFile);
|
||||
log.info("Artifact [{}] is written to [{}]", artifact.getCoordinates(), tmpFile.toURI().toURL().toString());
|
||||
repositoryService.addArtifact(tmpFile.toURI().toURL().toString()
|
||||
, coords.getGroupId()
|
||||
, coords.getArtifactId()
|
||||
, coords.getVersion()
|
||||
, coords.getType()
|
||||
, coords.getClassifier()
|
||||
, getName());
|
||||
log.info("Artifact [{}] is deployed to [{}]", artifact.getCoordinates(), getName());
|
||||
// Files.deleteIfExists(tmpFil)
|
||||
} catch (IOException e) {
|
||||
log.error("deployToCave", e);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
log.error("deployToCave", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
protected boolean isHealthy = false;
|
||||
|
||||
protected void deployToRemoteMaven(Artifact artifact) {
|
||||
try {
|
||||
initRemoteRepository();
|
||||
this.remoteRepository.deploy(artifact);
|
||||
} catch (Exception e) {
|
||||
log.error("deployToRemoteMaven", e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void initRemoteRepository() throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, MalformedURLException {
|
||||
if (this.remoteRepository == null) {
|
||||
this.remoteRepository = RemoteRepositoryFactory.create(new RemoteRepositoryDescriptor(repositoryDescriptor));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return repositoryDescriptor.getName();
|
||||
}
|
||||
protected RepositoryService repositoryService;
|
||||
|
||||
@Override
|
||||
public boolean isHealthy() {
|
||||
return this.isHealthy;
|
||||
}
|
||||
protected RepositoryDescriptor repositoryDescriptor;
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return repositoryDescriptor.isEnabled();
|
||||
}
|
||||
protected RemoteRepository remoteRepository = null;
|
||||
|
||||
@Override
|
||||
public boolean isReadOnly() {
|
||||
return repositoryDescriptor.isReadOnly();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSnapshotsAllowed() {
|
||||
return repositoryDescriptor.isSnapshots();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl() {
|
||||
return repositoryService.repository(getName()).getUrl();
|
||||
}
|
||||
public ArtifactRepositoryImpl() {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public void setRepositoryService(RepositoryService repositoryService) {
|
||||
this.repositoryService = repositoryService;
|
||||
}
|
||||
|
||||
public ArtifactRepositoryImpl(RepositoryDescriptor descriptor) {
|
||||
this();
|
||||
this.repositoryDescriptor = descriptor;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
Repository caveRepo = repositoryService.repository(repositoryDescriptor.getName());
|
||||
if (caveRepo == null) {
|
||||
caveRepo = createRepo();
|
||||
} else {
|
||||
caveRepo = checkUpdateRepo(caveRepo);
|
||||
}
|
||||
}
|
||||
|
||||
protected Repository createRepo() {
|
||||
Repository repo = null;
|
||||
try {
|
||||
repo = repositoryService.create(
|
||||
repositoryDescriptor.getName(),
|
||||
repositoryDescriptor.getLocation(),
|
||||
Strings.isNullOrEmpty(repositoryDescriptor.getUrl())
|
||||
? "/repositories/" + repositoryDescriptor.getName()
|
||||
: repositoryDescriptor.getUrl(),
|
||||
repositoryDescriptor.isProxy() && !Strings.isNullOrEmpty(repositoryDescriptor.getRemotes())
|
||||
? repositoryDescriptor.getRemotes()
|
||||
: null,
|
||||
/*
|
||||
repositoryDescriptor.isProxy() && !Strings.isNullOrEmpty(repositoryDescriptor.getRemotes())
|
||||
&& !Strings.isNullOrEmpty(repositoryDescriptor.getLocation())
|
||||
?repositoryDescriptor.isMirror()
|
||||
:false*/
|
||||
repositoryDescriptor.isMirror(),
|
||||
"karaf",
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
8);
|
||||
this.isHealthy = true;
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
log.error("createRepo", e);
|
||||
this.isHealthy = false;
|
||||
}
|
||||
return repo;
|
||||
}
|
||||
|
||||
protected Repository checkUpdateRepo(Repository repo) {
|
||||
try {
|
||||
log.info("repositoryDescriptor.getLocation(): [{}]; repo.getLocation(): [{}]",
|
||||
repositoryDescriptor.getLocation(), repo.getLocation());
|
||||
if (!Strings.isNullOrEmpty(repositoryDescriptor.getLocation())
|
||||
&& !repo.getLocation().equalsIgnoreCase(repositoryDescriptor.getLocation()))
|
||||
repositoryService.changeLocation(repositoryDescriptor.getName(), repositoryDescriptor.getLocation());
|
||||
if (!repo.getUrl().equalsIgnoreCase(repositoryDescriptor.getUrl())
|
||||
&& !Strings.isNullOrEmpty(repositoryDescriptor.getUrl()))
|
||||
repositoryService.changeUrl(repositoryDescriptor.getName(), repositoryDescriptor.getUrl());
|
||||
String repoProxy = repo.getProxy();
|
||||
boolean repoIsProxy = !Strings.isNullOrEmpty(repoProxy);
|
||||
if (repoIsProxy != repositoryDescriptor.isProxy()) {
|
||||
if (!repositoryDescriptor.isProxy())
|
||||
repositoryService.changeProxy(repositoryDescriptor.getName(), "", false);
|
||||
else
|
||||
repositoryService.changeProxy(repositoryDescriptor.getName(), repositoryDescriptor.getRemotes(),
|
||||
repositoryDescriptor.isMirror());
|
||||
}
|
||||
this.isHealthy = true;
|
||||
} catch (Exception e) {
|
||||
log.error("checkUpdateRepo", e);
|
||||
this.isHealthy = false;
|
||||
}
|
||||
return repo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeployedArtifact deploy(Artifact artifact) {
|
||||
if (isHealthy() && isEnabled() && !isReadOnly()) {
|
||||
return deployArtifact(artifact);
|
||||
}
|
||||
return new DeployedArtifactImpl(artifact);
|
||||
}
|
||||
|
||||
protected DeployedArtifact deployArtifact(Artifact artifact) {
|
||||
String location = "mvn:";
|
||||
|
||||
if (!repositoryDescriptor.isProxy() || repositoryDescriptor.isMirror())
|
||||
deployToCave(artifact);
|
||||
|
||||
if (repositoryDescriptor.isProxy())
|
||||
deployToRemoteMaven(artifact);
|
||||
|
||||
return new DeployedArtifactImpl(artifact, location + artifact.getCoordinates().toString());
|
||||
}
|
||||
|
||||
protected void deployToCave(Artifact artifact) {
|
||||
if (artifact.getContent() != null) {
|
||||
try {
|
||||
ArtifactCoordinates coords = artifact.getCoordinates();
|
||||
File tmpFile = File.createTempFile(getName() + "-", Calendar.getInstance().getTimeInMillis() + "");
|
||||
artifact.toFile(tmpFile);
|
||||
log.info("Artifact [{}] is written to [{}]", artifact.getCoordinates(),
|
||||
tmpFile.toURI().toURL().toString());
|
||||
repositoryService.addArtifact(tmpFile.toURI().toURL().toString(), coords.getGroupId(),
|
||||
coords.getArtifactId(), coords.getVersion(), coords.getType(), coords.getClassifier(),
|
||||
getName());
|
||||
log.info("Artifact [{}] is deployed to [{}]", artifact.getCoordinates(), getName());
|
||||
// Files.deleteIfExists(tmpFil)
|
||||
} catch (IOException e) {
|
||||
log.error("deployToCave", e);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
log.error("deployToCave", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void deployToRemoteMaven(Artifact artifact) {
|
||||
try {
|
||||
initRemoteRepository();
|
||||
this.remoteRepository.deploy(artifact);
|
||||
} catch (Exception e) {
|
||||
log.error("deployToRemoteMaven", e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void initRemoteRepository() throws NoSuchMethodException, SecurityException, InstantiationException,
|
||||
IllegalAccessException, IllegalArgumentException, InvocationTargetException, MalformedURLException {
|
||||
if (this.remoteRepository == null) {
|
||||
this.remoteRepository =
|
||||
RemoteRepositoryFactory.create(new RemoteRepositoryDescriptor(repositoryDescriptor));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return repositoryDescriptor.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHealthy() {
|
||||
return this.isHealthy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return repositoryDescriptor.isEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadOnly() {
|
||||
return repositoryDescriptor.isReadOnly();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSnapshotsAllowed() {
|
||||
return repositoryDescriptor.isSnapshots();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl() {
|
||||
return repositoryService.repository(getName()).getUrl();
|
||||
}
|
||||
|
||||
public void setRepositoryService(RepositoryService repositoryService) {
|
||||
this.repositoryService = repositoryService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSystem() {
|
||||
return this.repositoryDescriptor.isSystem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAvailableVersions(Artifact artifact) {
|
||||
|
||||
File f = new File(repositoryService.repository(getName()).getLocation());
|
||||
if (!f.exists())
|
||||
return null;
|
||||
Path target = Paths.get(
|
||||
f.getAbsoluteFile().toPath().toString(),
|
||||
artifact.getCoordinates().getGroupId().replace('.', File.separatorChar),
|
||||
artifact.getCoordinates().getArtifactId(),
|
||||
"maven-metadata-local.xml");
|
||||
File metadata = target.toFile();
|
||||
if (!metadata.exists())
|
||||
return null;
|
||||
try {
|
||||
Document xml = CommonXMLUtils.getDocument(target.toUri().toURL());
|
||||
NodeList nodes = xml.getElementsByTagName("version");
|
||||
List<String> result = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < nodes.getLength(); i++) {
|
||||
result.add(nodes.item(i).getTextContent());
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (MalformedURLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
log.error("getAvailableVersions", e);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
log.error("getAvailableVersions", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -25,34 +25,36 @@
|
||||
*/
|
||||
package ru.entaxy.platform.core.artifact.repository.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class RepositoryConfigurableHelper extends RepositoryDescriptor {
|
||||
import ru.entaxy.platform.core.artifact.repository.RepositoryDescriptorCollector;
|
||||
|
||||
private static final List<RepositoryConfigurableHelper> helpers = new ArrayList<>();
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(RepositoryConfigurableHelper.class);
|
||||
|
||||
RepositoryConfigurableHelperCollector collector;
|
||||
public class RepositoryConfigurableHelper extends RepositoryDescriptorImpl {
|
||||
|
||||
private static final Map<String, RepositoryConfigurableHelper> helpers = new LinkedHashMap<>();
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(RepositoryConfigurableHelper.class);
|
||||
|
||||
RepositoryDescriptorCollector collector;
|
||||
|
||||
public void init() {
|
||||
if (collector != null)
|
||||
collector.addRepositoryDescriptor(this);
|
||||
log.info("Helper with name [{}] created", name);
|
||||
RepositoryConfigurableHelper.helpers.put(this.getName(), this);
|
||||
log.info("Total helpers: {}:\n{}",
|
||||
"" + RepositoryConfigurableHelper.helpers.size(),
|
||||
RepositoryConfigurableHelper.helpers.values().stream()
|
||||
.map((h) -> h.getName()).collect(Collectors.joining("\n\t", "\t", "")));
|
||||
}
|
||||
|
||||
public void setCollector(RepositoryDescriptorCollector collector) {
|
||||
this.collector = collector;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
if (collector != null)
|
||||
collector.addConfigurableHelper(this);
|
||||
log.info("Helper with name [{}] created", name);
|
||||
RepositoryConfigurableHelper.helpers.add(this);
|
||||
log.info("Total helpers: {}:\n{}",
|
||||
"" + RepositoryConfigurableHelper.helpers.size(),
|
||||
RepositoryConfigurableHelper.helpers.stream()
|
||||
.map((h)->h.getName()).collect(Collectors.joining("\n\t", "\t", "")));
|
||||
}
|
||||
|
||||
public void setCollector(RepositoryConfigurableHelperCollector collector) {
|
||||
this.collector = collector;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,33 +0,0 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
* rights to the Software and any copies are the property of the Copyright Holder. Unless
|
||||
* it is explicitly allowed the Copyright Holder, the User is prohibited from using the
|
||||
* Software for commercial purposes to provide services to third parties.
|
||||
*
|
||||
* The Copyright Holder hereby declares that the Software is provided on an "AS IS".
|
||||
* Under no circumstances does the Copyright Holder guarantee or promise that the
|
||||
* Software provided by him will be suitable or not suitable for the specific purposes
|
||||
* of the User, that the Software will meet all commercial and personal subjective
|
||||
* expectations of the User, that the Software will work properly, without technical
|
||||
* errors, quickly and uninterruptedly.
|
||||
*
|
||||
* Under no circumstances shall the Copyright Holder or its Affiliates is not liable
|
||||
* to the User for any direct or indirect losses of the User, his expenses or actual
|
||||
* damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
|
||||
* or damage to data, property, etc.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.artifact.repository.impl;
|
||||
|
||||
/*
|
||||
* Internal interface to collect helpers managed by config files
|
||||
*/
|
||||
public interface RepositoryConfigurableHelperCollector {
|
||||
public void addConfigurableHelper(RepositoryConfigurableHelper helper);
|
||||
}
|
@ -1,151 +0,0 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
* rights to the Software and any copies are the property of the Copyright Holder. Unless
|
||||
* it is explicitly allowed the Copyright Holder, the User is prohibited from using the
|
||||
* Software for commercial purposes to provide services to third parties.
|
||||
*
|
||||
* The Copyright Holder hereby declares that the Software is provided on an "AS IS".
|
||||
* Under no circumstances does the Copyright Holder guarantee or promise that the
|
||||
* Software provided by him will be suitable or not suitable for the specific purposes
|
||||
* of the User, that the Software will meet all commercial and personal subjective
|
||||
* expectations of the User, that the Software will work properly, without technical
|
||||
* errors, quickly and uninterruptedly.
|
||||
*
|
||||
* Under no circumstances shall the Copyright Holder or its Affiliates is not liable
|
||||
* to the User for any direct or indirect losses of the User, his expenses or actual
|
||||
* damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
|
||||
* or damage to data, property, etc.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.platform.core.artifact.repository.impl;
|
||||
|
||||
public class RepositoryDescriptor {
|
||||
|
||||
protected String name;
|
||||
String location;
|
||||
String url;
|
||||
boolean isProxy;
|
||||
boolean isMirror;
|
||||
String remotes;
|
||||
boolean isReadOnly = false;
|
||||
boolean copyOnChange;
|
||||
String username = "";
|
||||
String password = "";
|
||||
|
||||
boolean isSnapshots = false;
|
||||
|
||||
boolean isEnabled = true;
|
||||
|
||||
String remoteHostSuffix = "";
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocation(String location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public boolean isProxy() {
|
||||
return isProxy;
|
||||
}
|
||||
|
||||
public void setProxy(boolean isProxy) {
|
||||
this.isProxy = isProxy;
|
||||
}
|
||||
|
||||
public boolean isMirror() {
|
||||
return isMirror;
|
||||
}
|
||||
|
||||
public void setMirror(boolean isMirror) {
|
||||
this.isMirror = isMirror;
|
||||
}
|
||||
|
||||
public boolean isSnapshots() {
|
||||
return isSnapshots;
|
||||
}
|
||||
|
||||
public void setSnapshots(boolean isSnapshots) {
|
||||
this.isSnapshots = isSnapshots;
|
||||
}
|
||||
|
||||
public String getRemotes() {
|
||||
return remotes;
|
||||
}
|
||||
|
||||
public void setRemotes(String remotes) {
|
||||
this.remotes = remotes;
|
||||
}
|
||||
|
||||
public boolean isReadOnly() {
|
||||
return isReadOnly;
|
||||
}
|
||||
|
||||
public void setReadOnly(boolean isReadOnly) {
|
||||
this.isReadOnly = isReadOnly;
|
||||
}
|
||||
|
||||
public boolean isCopyOnChange() {
|
||||
return copyOnChange;
|
||||
}
|
||||
|
||||
public void setCopyOnChange(boolean copyOnChange) {
|
||||
this.copyOnChange = copyOnChange;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return isEnabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean isEnabled) {
|
||||
this.isEnabled = isEnabled;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getRemoteHostSuffix() {
|
||||
return remoteHostSuffix;
|
||||
}
|
||||
|
||||
public void setRemoteHostSuffix(String remoteHostSuffix) {
|
||||
this.remoteHostSuffix = remoteHostSuffix;
|
||||
}
|
||||
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -25,6 +25,8 @@
|
||||
*/
|
||||
package ru.entaxy.platform.core.artifact.repository.impl.remote;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.auth.AuthenticationException;
|
||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||
@ -41,84 +43,87 @@ import org.apache.http.entity.mime.MultipartEntityBuilder;
|
||||
import org.apache.http.impl.auth.BasicScheme;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
|
||||
import org.apache.http.impl.conn.BasicHttpClientConnectionManager;
|
||||
import org.apache.http.ssl.SSLContexts;
|
||||
import org.apache.http.ssl.TrustStrategy;
|
||||
|
||||
import ru.entaxy.platform.base.support.CommonUtils;
|
||||
import ru.entaxy.platform.core.artifact.Artifact;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
|
||||
public class NexusRepository extends AbstractRemoteRepository {
|
||||
|
||||
private static final String DEFAULT_REPOSITORY_NAME = "entaxy";
|
||||
private static final String DEFAULT_REPOSITORY_NAME = "entaxy";
|
||||
private static final String NEXUS_ADDRESS = "/service/rest/v1";
|
||||
|
||||
String username;
|
||||
String password;
|
||||
String host;
|
||||
String repositoryName;
|
||||
|
||||
String hostSuffix;
|
||||
|
||||
String apiAddress;
|
||||
|
||||
@Override
|
||||
public void init(RemoteRepositoryDescriptor repositoryDescriptor) {
|
||||
this.host = repositoryDescriptor.getHost();
|
||||
|
||||
String repositoryPath = repositoryDescriptor.getRepositoryPath();
|
||||
if (CommonUtils.isValid(repositoryPath))
|
||||
repositoryPath = repositoryPath.trim();
|
||||
if (!CommonUtils.isValid(repositoryPath))
|
||||
// TODO throw exception
|
||||
return;
|
||||
if (repositoryPath.endsWith("/"))
|
||||
repositoryPath = repositoryPath.substring(0, repositoryPath.length()-1);
|
||||
String[] splitted = repositoryPath.split("/");
|
||||
this.repositoryName = splitted[splitted.length-1];
|
||||
if (!CommonUtils.isValid(repositoryName))
|
||||
this.repositoryName = DEFAULT_REPOSITORY_NAME;
|
||||
|
||||
this.hostSuffix = repositoryDescriptor.getHostSuffix();
|
||||
|
||||
this.apiAddress = this.host + this.hostSuffix + NEXUS_ADDRESS;
|
||||
|
||||
this.username = repositoryDescriptor.getUsername();
|
||||
this.password = repositoryDescriptor.getPassword();
|
||||
}
|
||||
String username;
|
||||
String password;
|
||||
String host;
|
||||
String repositoryName;
|
||||
|
||||
@Override
|
||||
public void deploy(Artifact artifact) throws Exception {
|
||||
String hostSuffix;
|
||||
|
||||
//TODO: manage via config
|
||||
TrustStrategy acceptingTrustStrategy = (cert, authType) -> true;
|
||||
SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build();
|
||||
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext,
|
||||
NoopHostnameVerifier.INSTANCE);
|
||||
String apiAddress;
|
||||
|
||||
Registry<ConnectionSocketFactory> socketFactoryRegistry =
|
||||
RegistryBuilder.<ConnectionSocketFactory> create()
|
||||
.register("https", sslsf)
|
||||
.register("http", new PlainConnectionSocketFactory())
|
||||
.build();
|
||||
boolean isSystem;
|
||||
|
||||
BasicHttpClientConnectionManager connectionManager =
|
||||
new BasicHttpClientConnectionManager(socketFactoryRegistry);
|
||||
@Override
|
||||
public void init(RemoteRepositoryDescriptor repositoryDescriptor) {
|
||||
this.host = repositoryDescriptor.getHost();
|
||||
|
||||
HttpPost httpPost = new HttpPost(this.apiAddress + "/components?repository=" + this.repositoryName);
|
||||
String repositoryPath = repositoryDescriptor.getRepositoryPath();
|
||||
if (CommonUtils.isValid(repositoryPath))
|
||||
repositoryPath = repositoryPath.trim();
|
||||
if (!CommonUtils.isValid(repositoryPath))
|
||||
// TODO throw exception
|
||||
return;
|
||||
if (repositoryPath.endsWith("/"))
|
||||
repositoryPath = repositoryPath.substring(0, repositoryPath.length() - 1);
|
||||
String[] splitted = repositoryPath.split("/");
|
||||
this.repositoryName = splitted[splitted.length - 1];
|
||||
if (!CommonUtils.isValid(repositoryName))
|
||||
this.repositoryName = DEFAULT_REPOSITORY_NAME;
|
||||
|
||||
addAuth(httpPost);
|
||||
httpPost.setEntity(createMultipartEntityBuilder(artifact).build());
|
||||
this.hostSuffix = repositoryDescriptor.getHostSuffix();
|
||||
|
||||
try (CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(sslsf)
|
||||
.setConnectionManager(connectionManager).build();
|
||||
CloseableHttpResponse response = httpClient.execute(httpPost)) {
|
||||
checkAnswer(response);
|
||||
this.apiAddress = this.host + this.hostSuffix + NEXUS_ADDRESS;
|
||||
|
||||
this.username = repositoryDescriptor.getUsername();
|
||||
this.password = repositoryDescriptor.getPassword();
|
||||
|
||||
this.isSystem = repositoryDescriptor.isSystem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deploy(Artifact artifact) throws Exception {
|
||||
|
||||
// TODO: manage via config
|
||||
TrustStrategy acceptingTrustStrategy = (cert, authType) -> true;
|
||||
SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build();
|
||||
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext,
|
||||
NoopHostnameVerifier.INSTANCE);
|
||||
|
||||
Registry<ConnectionSocketFactory> socketFactoryRegistry =
|
||||
RegistryBuilder.<ConnectionSocketFactory>create()
|
||||
.register("https", sslsf)
|
||||
.register("http", new PlainConnectionSocketFactory())
|
||||
.build();
|
||||
|
||||
try (BasicHttpClientConnectionManager connectionManager =
|
||||
new BasicHttpClientConnectionManager(socketFactoryRegistry)) {
|
||||
|
||||
HttpPost httpPost = new HttpPost(this.apiAddress + "/components?repository=" + this.repositoryName);
|
||||
|
||||
addAuth(httpPost);
|
||||
httpPost.setEntity(createMultipartEntityBuilder(artifact).build());
|
||||
|
||||
try (CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(sslsf)
|
||||
.setConnectionManager(connectionManager).build();
|
||||
CloseableHttpResponse response = httpClient.execute(httpPost)) {
|
||||
checkAnswer(response);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void checkAnswer(CloseableHttpResponse response) throws HttpResponseException {
|
||||
if (response.getStatusLine().getStatusCode() != 204 && response.getStatusLine().getStatusCode() != 200) {
|
||||
@ -128,10 +133,10 @@ public class NexusRepository extends AbstractRemoteRepository {
|
||||
}
|
||||
|
||||
private void addAuth(HttpRequest httpRequest) throws AuthenticationException {
|
||||
if (CommonUtils.isValid(username)) {
|
||||
UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username, password);
|
||||
httpRequest.addHeader(new BasicScheme().authenticate(creds, httpRequest, null));
|
||||
}
|
||||
if (CommonUtils.isValid(username)) {
|
||||
UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username, password);
|
||||
httpRequest.addHeader(new BasicScheme().authenticate(creds, httpRequest, null));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -142,8 +147,8 @@ public class NexusRepository extends AbstractRemoteRepository {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
*/
|
||||
|
||||
*/
|
||||
|
||||
private MultipartEntityBuilder createMultipartEntityBuilder(Artifact artifact) {
|
||||
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
|
||||
builder.addBinaryBody("maven2.asset1", artifact.asByteArray());
|
||||
@ -155,6 +160,6 @@ public class NexusRepository extends AbstractRemoteRepository {
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -28,72 +28,79 @@ package ru.entaxy.platform.core.artifact.repository.impl.remote;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import ru.entaxy.platform.core.artifact.repository.impl.RepositoryDescriptor;
|
||||
import ru.entaxy.platform.core.artifact.repository.RepositoryDescriptor;
|
||||
|
||||
public class RemoteRepositoryDescriptor {
|
||||
|
||||
String type = "nexus";
|
||||
|
||||
String host;
|
||||
String hostSuffix;
|
||||
String username;
|
||||
String password;
|
||||
String repositoryPath;
|
||||
|
||||
public RemoteRepositoryDescriptor(RepositoryDescriptor repositoryDescriptor) throws MalformedURLException {
|
||||
String repositoryUrl = repositoryDescriptor.getRemotes().trim();
|
||||
URL url = new URL(repositoryUrl);
|
||||
this.host = url.getProtocol() + "://" + url.getHost();
|
||||
if (url.getPort()>0)
|
||||
this.host += ":" + url.getPort();
|
||||
this.hostSuffix = repositoryDescriptor.getRemoteHostSuffix();
|
||||
this.repositoryPath = url.getPath();
|
||||
this.username = repositoryDescriptor.getUsername();
|
||||
this.password = repositoryDescriptor.getPassword();
|
||||
}
|
||||
String type = "nexus";
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
String host;
|
||||
String hostSuffix;
|
||||
String username;
|
||||
String password;
|
||||
String repositoryPath;
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
boolean isSystem;
|
||||
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
public RemoteRepositoryDescriptor(RepositoryDescriptor repositoryDescriptor) throws MalformedURLException {
|
||||
String repositoryUrl = repositoryDescriptor.getRemotes().trim();
|
||||
URL url = new URL(repositoryUrl);
|
||||
this.host = url.getProtocol() + "://" + url.getHost();
|
||||
if (url.getPort() > 0)
|
||||
this.host += ":" + url.getPort();
|
||||
this.hostSuffix = repositoryDescriptor.getRemoteHostSuffix();
|
||||
this.repositoryPath = url.getPath();
|
||||
this.username = repositoryDescriptor.getUsername();
|
||||
this.password = repositoryDescriptor.getPassword();
|
||||
this.isSystem = repositoryDescriptor.isSystem();
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public String getRepositoryPath() {
|
||||
return repositoryPath;
|
||||
}
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public void setRepositoryPath(String repositoryName) {
|
||||
this.repositoryPath = repositoryName;
|
||||
}
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public String getHostSuffix() {
|
||||
return hostSuffix;
|
||||
}
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getRepositoryPath() {
|
||||
return repositoryPath;
|
||||
}
|
||||
|
||||
public void setRepositoryPath(String repositoryName) {
|
||||
this.repositoryPath = repositoryName;
|
||||
}
|
||||
|
||||
public String getHostSuffix() {
|
||||
return hostSuffix;
|
||||
}
|
||||
|
||||
public void setHostSuffix(String hostSuffix) {
|
||||
this.hostSuffix = hostSuffix;
|
||||
}
|
||||
|
||||
public boolean isSystem() {
|
||||
return isSystem;
|
||||
}
|
||||
|
||||
public void setHostSuffix(String hostSuffix) {
|
||||
this.hostSuffix = hostSuffix;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -25,18 +25,23 @@
|
||||
*/
|
||||
package ru.entaxy.platform.core.artifact.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import ru.entaxy.platform.core.artifact.Artifact;
|
||||
import ru.entaxy.platform.core.artifact.DeployedArtifact;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.InstallersWithDefaults;
|
||||
import ru.entaxy.platform.core.artifact.repository.ArtifactRepository;
|
||||
|
||||
public interface ArtifactService {
|
||||
|
||||
public DeployedArtifact deployLocal(Artifact artifact);
|
||||
public DeployedArtifact deployShared(Artifact artifact);
|
||||
|
||||
public ArtifactRepository getRepository(String name);
|
||||
|
||||
public InstallersWithDefaults installers();
|
||||
|
||||
|
||||
public DeployedArtifact deployLocal(Artifact artifact);
|
||||
|
||||
public DeployedArtifact deployShared(Artifact artifact);
|
||||
|
||||
public ArtifactRepository getRepository(String name);
|
||||
|
||||
public List<ArtifactRepository> getRepositories();
|
||||
|
||||
public InstallersWithDefaults installers();
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* artifact-management
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -25,117 +25,142 @@
|
||||
*/
|
||||
package ru.entaxy.platform.core.artifact.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.karaf.cave.repository.RepositoryService;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.FrameworkUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ru.entaxy.platform.core.artifact.Artifact;
|
||||
import ru.entaxy.platform.core.artifact.ArtifactCoordinates;
|
||||
import ru.entaxy.platform.core.artifact.DeployedArtifact;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.InstallersWithDefaults;
|
||||
import ru.entaxy.platform.core.artifact.installer.builder.impl.InstallersWithDefaultsImpl;
|
||||
import ru.entaxy.platform.core.artifact.repository.ArtifactRepository;
|
||||
import ru.entaxy.platform.core.artifact.repository.RepositoryDescriptor;
|
||||
import ru.entaxy.platform.core.artifact.repository.RepositoryDescriptorCollector;
|
||||
import ru.entaxy.platform.core.artifact.repository.impl.ArtifactRepositoryImpl;
|
||||
import ru.entaxy.platform.core.artifact.repository.impl.DeployedArtifactImpl;
|
||||
import ru.entaxy.platform.core.artifact.repository.impl.RepositoryConfigurableHelper;
|
||||
import ru.entaxy.platform.core.artifact.repository.impl.RepositoryConfigurableHelperCollector;
|
||||
import ru.entaxy.platform.core.artifact.repository.impl.RepositoryRegistrator;
|
||||
import ru.entaxy.platform.core.artifact.service.ArtifactService;
|
||||
|
||||
public class ArtifactServiceImpl implements ArtifactService, RepositoryConfigurableHelperCollector {
|
||||
|
||||
protected Map<String, ArtifactRepository> repositories = new HashMap<>();
|
||||
|
||||
protected BundleContext bundleContext;
|
||||
|
||||
protected RepositoryService repositoryService;
|
||||
|
||||
protected InstallersWithDefaultsImpl installers;
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(ArtifactServiceImpl.class);
|
||||
|
||||
public ArtifactServiceImpl() {
|
||||
installers = new InstallersWithDefaultsImpl();
|
||||
}
|
||||
|
||||
public void addRepository(ArtifactRepository repository) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addConfigurableHelper(RepositoryConfigurableHelper helper) {
|
||||
log.info("Added helper for repository [{}]", helper.getName());
|
||||
if (!repositories.containsKey(helper.getName())) {
|
||||
ArtifactRepository repo = createRepository(helper);
|
||||
this.repositories.put(repo.getName(), repo);
|
||||
}
|
||||
}
|
||||
public class ArtifactServiceImpl implements ArtifactService, RepositoryDescriptorCollector {
|
||||
|
||||
protected ArtifactRepository createRepository(RepositoryConfigurableHelper helper) {
|
||||
ArtifactRepositoryImpl repo = new ArtifactRepositoryImpl(helper);
|
||||
synchronized (repositories) {
|
||||
repositories.put(repo.getName(), repo);
|
||||
}
|
||||
repo.setRepositoryService(repositoryService);
|
||||
repo.init();
|
||||
return repo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeployedArtifact deployLocal(Artifact artifact) {
|
||||
return deploy(artifact, ArtifactRepository.REPO_NAME_LOCAL);
|
||||
}
|
||||
protected Map<String, ArtifactRepository> repositories = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public DeployedArtifact deployShared(Artifact artifact) {
|
||||
return deploy(artifact, ArtifactRepository.REPO_NAME_SHARED);
|
||||
}
|
||||
protected BundleContext bundleContext;
|
||||
|
||||
// TODO refactor to using repository exceptions if needed
|
||||
protected DeployedArtifact deploy(Artifact artifact, String repositoryName) {
|
||||
String error = "Repository [" + repositoryName + "] not found";
|
||||
if (repositories.containsKey(repositoryName)) {
|
||||
ArtifactRepository repo = repositories.get(repositoryName);
|
||||
error = String.format("Cannot deploy artifact [%s] to repository [" + repositoryName + "]", artifact.getCoordinates().toString());
|
||||
if (repo.isHealthy())
|
||||
if (repo.isEnabled())
|
||||
if (!repo.isReadOnly())
|
||||
return repo.deploy(artifact);
|
||||
else
|
||||
error += ": repository is readonly";
|
||||
else
|
||||
error += ": repository is disabled";
|
||||
else
|
||||
error += ": repository is not healthy";
|
||||
}
|
||||
log.error(error);
|
||||
return new DeployedArtifactImpl(artifact);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArtifactRepository getRepository(String name) {
|
||||
return this.repositories.get(name);
|
||||
}
|
||||
protected RepositoryService repositoryService;
|
||||
|
||||
public void setBundleContext(BundleContext bundleContext) {
|
||||
this.bundleContext = bundleContext;
|
||||
}
|
||||
protected InstallersWithDefaultsImpl installers;
|
||||
|
||||
public void setRepositoryService(RepositoryService repositoryService) {
|
||||
this.repositoryService = repositoryService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstallersWithDefaults installers() {
|
||||
return this.installers;
|
||||
}
|
||||
private boolean httpEnabled;
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(ArtifactServiceImpl.class);
|
||||
|
||||
public ArtifactServiceImpl() {
|
||||
installers = new InstallersWithDefaultsImpl();
|
||||
}
|
||||
|
||||
public void addRepository(ArtifactRepository repository) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRepositoryDescriptor(RepositoryDescriptor helper) {
|
||||
log.info("Added descriptor for repository [{}]", helper.getName());
|
||||
if (!repositories.containsKey(helper.getName())) {
|
||||
ArtifactRepository repo = createRepository(helper);
|
||||
this.repositories.put(repo.getName(), repo);
|
||||
if (helper.isLookupEnabled())
|
||||
RepositoryRegistrator.INSTANCE.addRepository(repo, httpEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRepositoryDescriptor(RepositoryDescriptor helper) {
|
||||
// FIX for first start
|
||||
if (repositories != null && helper != null) {
|
||||
if (helper.isLookupEnabled())
|
||||
RepositoryRegistrator.INSTANCE.removeRepository(repositories.get(helper.getName()));
|
||||
repositories.remove(helper.getName());
|
||||
}
|
||||
}
|
||||
|
||||
protected ArtifactRepository createRepository(RepositoryDescriptor helper) {
|
||||
ArtifactRepositoryImpl repo = new ArtifactRepositoryImpl(helper);
|
||||
synchronized (repositories) {
|
||||
repositories.put(repo.getName(), repo);
|
||||
}
|
||||
repo.setRepositoryService(repositoryService);
|
||||
repo.init();
|
||||
return repo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeployedArtifact deployLocal(Artifact artifact) {
|
||||
return deploy(artifact, ArtifactRepository.REPO_NAME_LOCAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeployedArtifact deployShared(Artifact artifact) {
|
||||
return deploy(artifact, ArtifactRepository.REPO_NAME_SHARED);
|
||||
}
|
||||
|
||||
// TODO refactor to using repository exceptions if needed
|
||||
protected DeployedArtifact deploy(Artifact artifact, String repositoryName) {
|
||||
String error = "Repository [" + repositoryName + "] not found";
|
||||
if (repositories.containsKey(repositoryName)) {
|
||||
ArtifactRepository repo = repositories.get(repositoryName);
|
||||
error = String.format("Cannot deploy artifact [%s] to repository [" + repositoryName + "]",
|
||||
artifact.getCoordinates().toString());
|
||||
if (repo.isHealthy())
|
||||
if (repo.isEnabled())
|
||||
if (!repo.isReadOnly())
|
||||
return repo.deploy(artifact);
|
||||
else
|
||||
error += ": repository is readonly";
|
||||
else
|
||||
error += ": repository is disabled";
|
||||
else
|
||||
error += ": repository is not healthy";
|
||||
}
|
||||
log.error(error);
|
||||
return new DeployedArtifactImpl(artifact);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArtifactRepository getRepository(String name) {
|
||||
return this.repositories.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ArtifactRepository> getRepositories() {
|
||||
return new ArrayList<>(this.repositories.values());
|
||||
}
|
||||
|
||||
public void setBundleContext(BundleContext bundleContext) {
|
||||
this.bundleContext = bundleContext;
|
||||
}
|
||||
|
||||
public void setRepositoryService(RepositoryService repositoryService) {
|
||||
this.repositoryService = repositoryService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstallersWithDefaults installers() {
|
||||
return this.installers;
|
||||
}
|
||||
|
||||
public void setInstallers(InstallersWithDefaultsImpl installers) {
|
||||
this.installers = installers;
|
||||
}
|
||||
|
||||
public void setHttpEnabled(boolean httpEnabled) {
|
||||
this.httpEnabled = httpEnabled;
|
||||
}
|
||||
|
||||
public void setInstallers(InstallersWithDefaultsImpl installers) {
|
||||
this.installers = installers;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
# ~~~~~~licensing~~~~~~
|
||||
# artifact-management
|
||||
# ==========
|
||||
# Copyright (C) 2020 - 2023 EmDev LLC
|
||||
# Copyright (C) 2020 - 2024 EmDev LLC
|
||||
# ==========
|
||||
# You may not use this file except in accordance with the License Terms of the Copyright
|
||||
# Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -3,7 +3,7 @@
|
||||
~~~~~~licensing~~~~~~
|
||||
uniform-service-exchange-endpoint
|
||||
==========
|
||||
Copyright (C) 2020 - 2023 EmDev LLC
|
||||
Copyright (C) 2020 - 2024 EmDev LLC
|
||||
==========
|
||||
You may not use this file except in accordance with the License Terms of the Copyright
|
||||
Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -71,7 +71,12 @@
|
||||
</cm:default-properties>
|
||||
</cm:property-placeholder>
|
||||
|
||||
|
||||
<cm:property-placeholder persistent-id="org.ops4j.pax.web" placeholder-prefix="$web{" update-strategy="reload">
|
||||
<cm:default-properties>
|
||||
<cm:property name="org.osgi.service.http.enabled" value="true"/>
|
||||
</cm:default-properties>
|
||||
</cm:property-placeholder>
|
||||
|
||||
<reference id="repositoryService" availability="mandatory" interface="org.apache.karaf.cave.repository.RepositoryService">
|
||||
</reference>
|
||||
|
||||
@ -79,11 +84,22 @@
|
||||
<property name="bundleContext" ref="blueprintBundleContext"></property>
|
||||
<property name="repositoryService" ref="repositoryService"></property>
|
||||
<property name="installers" ref="installers"></property>
|
||||
<property name="httpEnabled" value="$web{org.osgi.service.http.enabled}"/>
|
||||
</bean>
|
||||
|
||||
<service interface="ru.entaxy.platform.core.artifact.service.ArtifactService" activation="eager" ref="artifactServiceImpl">
|
||||
<service activation="eager" ref="artifactServiceImpl">
|
||||
<interfaces>
|
||||
<value>ru.entaxy.platform.core.artifact.service.ArtifactService</value>
|
||||
<value>ru.entaxy.platform.core.artifact.repository.RepositoryDescriptorCollector</value>
|
||||
</interfaces>
|
||||
</service>
|
||||
|
||||
<!-- collect custom repositories created at runtime -->
|
||||
<reference-list activation="eager" availability="optional" interface="ru.entaxy.platform.core.artifact.repository.RepositoryDescriptor">
|
||||
<reference-listener ref="artifactServiceImpl" bind-method="addRepositoryDescriptor" unbind-method="removeRepositoryDescriptor">
|
||||
</reference-listener>
|
||||
</reference-list>
|
||||
|
||||
<!-- cm:managed-service-factory factory-pid="ru.entaxy.platform.artifact.repository" interface="java.lang.Object">
|
||||
<cm:managed-component class="ru.entaxy.platform.core.artifact.repository.impl.RepositoryConfigurableHelper"
|
||||
init-method="init">
|
||||
|
Reference in New Issue
Block a user