Skip to content

Commit

Permalink
opt the maven build plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
rocky committed Oct 8, 2022
1 parent b5ce3fe commit d704db6
Show file tree
Hide file tree
Showing 20 changed files with 80 additions and 96 deletions.
2 changes: 1 addition & 1 deletion lattice-model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lattice</artifactId>
<groupId>org.hiforce.lattice</groupId>
<version>1.0.9</version>
<version>1.0.9.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>lattice-model</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion lattice-remote/lattice-remote-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lattice</artifactId>
<groupId>org.hiforce.lattice</groupId>
<version>1.0.9</version>
<version>1.0.9.1</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion lattice-remote/lattice-remote-container/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lattice</artifactId>
<groupId>org.hiforce.lattice</groupId>
<version>1.0.9</version>
<version>1.0.9.1</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lattice</artifactId>
<groupId>org.hiforce.lattice</groupId>
<version>1.0.9</version>
<version>1.0.9.1</version>
<relativePath>../../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion lattice-remote/lattice-remote-runner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lattice</artifactId>
<groupId>org.hiforce.lattice</groupId>
<version>1.0.9</version>
<version>1.0.9.1</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion lattice-remote/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lattice</artifactId>
<groupId>org.hiforce.lattice</groupId>
<version>1.0.9</version>
<version>1.0.9.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion lattice-runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lattice</artifactId>
<groupId>org.hiforce.lattice</groupId>
<version>1.0.9</version>
<version>1.0.9.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion lattice-tools/lattice-load-config-res/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lattice-tools</artifactId>
<groupId>org.hiforce.lattice</groupId>
<version>1.0.9</version>
<version>1.0.9.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lattice-maven-build</artifactId>
<groupId>org.hiforce.lattice</groupId>
<version>1.0.9</version>
<version>1.0.9.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ public class AbilityInstInfo extends BaseInfo {

@Getter
private final List<ExtensionInfo> extensions = Lists.newArrayList();

@Getter
@Setter
private DependencyInfo dependency;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ public class LatticeInfo implements Serializable {

private static final long serialVersionUID = 6289372399096534060L;

@Getter
@Setter
private String groupId;

@Getter
@Setter
private String artifactId;

@Getter
@Setter
private String version;

@Getter
@Setter
private AbilitySet ability = new AbilitySet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lattice-maven-build</artifactId>
<groupId>org.hiforce.lattice</groupId>
<version>1.0.9</version>
<version>1.0.9.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>maven-plugin</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public void execute() throws MojoExecutionException, MojoFailureException {
getLog().info(">> LatticeBuildPlugin start....");
getLog().info(">> Project: " + mavenProject.getName());

latticeInfo.setGroupId(mavenProject.getGroupId());
latticeInfo.setArtifactId(mavenProject.getArtifactId());
latticeInfo.setVersion(mavenProject.getVersion());

totalClassLoader = loadClassLoader(false, false);
projectClassLoader = loadClassLoader(true, false);
importClassLoader = loadClassLoader(false, true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
package org.hiforce.lattice.maven.builder;

import org.apache.commons.lang3.StringUtils;
import org.apache.maven.model.Dependency;
import org.hifforce.lattice.model.ability.IAbility;
import org.hifforce.lattice.model.register.AbilityInstSpec;
import org.hifforce.lattice.model.register.AbilitySpec;
import org.hifforce.lattice.model.register.ExtensionPointSpec;
import org.hiforce.lattice.maven.LatticeBuildPlugin;
import org.hiforce.lattice.maven.model.*;
import org.hiforce.lattice.runtime.Lattice;
import org.hiforce.lattice.maven.model.AbilityInfo;
import org.hiforce.lattice.maven.model.AbilityInstInfo;
import org.hiforce.lattice.maven.model.ExtParam;
import org.hiforce.lattice.maven.model.ExtensionInfo;
import org.hiforce.lattice.runtime.ability.register.AbilityBuildRequest;
import org.hiforce.lattice.runtime.ability.register.AbilityRegister;

import java.io.File;
import java.lang.reflect.Parameter;
import java.net.URI;
import java.security.CodeSource;
import java.security.ProtectionDomain;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -59,34 +55,15 @@ private List<AbilityInfo> getLoadAbilityClass(List<String> classNames) {
@SuppressWarnings("all")
private AbilityInfo buildAbilityInfo(AbilitySpec abilitySpec) {
AbilityInfo info = new AbilityInfo();
List<Dependency> dependencies = getPlugin().getMavenProject().getRuntimeDependencies();

Class<?> abilityClass = abilitySpec.getAbilityClass();
info.setCode(abilitySpec.getCode());
info.setName(abilitySpec.getName());
info.setClassName(abilityClass.getName());

info.getInstances().addAll(abilitySpec.getAbilityInstances().stream()
.map(p -> buildAbilityInstInfo(p)).collect(Collectors.toList()));

try {
ProtectionDomain protectionDomain = abilityClass.getProtectionDomain();
CodeSource codeSource = protectionDomain.getCodeSource();
URI location = (codeSource != null) ? codeSource.getLocation().toURI() : null;
String path = (location != null) ? location.getSchemeSpecificPart() : null;

File file = new File(path);
DependencyInfo dependency = dependencies.stream()
.filter(p -> StringUtils.equals(file.getName(),
String.format("%s-%s.jar", p.getArtifactId(), p.getVersion())))
.findFirst()
.map(p -> DependencyInfo.of(p.getGroupId(), p.getArtifactId(), p.getVersion()))
.orElse(null);
if (null != dependency) {
info.setDependency(dependency);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
info.setDependency(getDependencyInfo(abilityClass));
return info;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.model.Dependency;
import org.apache.maven.plugin.logging.Log;
import org.hifforce.lattice.annotation.model.ExtensionAnnotation;
import org.hifforce.lattice.model.ability.IBusinessExt;
import org.hifforce.lattice.model.register.RealizationSpec;
import org.hiforce.lattice.maven.LatticeBuildPlugin;
import org.hiforce.lattice.maven.model.DependencyInfo;
import org.hiforce.lattice.maven.model.ExtensionInfo;
import org.hiforce.lattice.maven.model.RealizationInfo;
import org.hiforce.lattice.runtime.Lattice;

import java.io.File;
import java.lang.reflect.Method;
import java.net.URI;
import java.security.CodeSource;
import java.security.ProtectionDomain;
import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -91,6 +98,37 @@ public static RealizationInfo buildRealizationInfo(RealizationSpec spec) {
return info;
}

@SuppressWarnings("unchecked")
public DependencyInfo getDependencyInfo(Class<?> targetClass) {
if (null == targetClass) {
return null;
}

try {

ProtectionDomain protectionDomain = targetClass.getProtectionDomain();
CodeSource codeSource = protectionDomain.getCodeSource();
URI location = (codeSource != null) ? codeSource.getLocation().toURI() : null;
String path = (location != null) ? location.getSchemeSpecificPart() : null;
if (null == path) {
return null;
}

File file = new File(path);

List<Dependency> dependencies = getPlugin().getMavenProject().getRuntimeDependencies();
return dependencies.stream()
.filter(p -> StringUtils.equals(file.getName(),
String.format("%s-%s.jar", p.getArtifactId(), p.getVersion())))
.findFirst()
.map(p -> DependencyInfo.of(p.getGroupId(), p.getArtifactId(), p.getVersion()))
.orElse(null);
} catch (Exception ex) {
getLog().error(ex.getMessage(), ex);
return null;
}
}

public List<ExtensionInfo> buildCustomizedExtensionInfos(IBusinessExt businessExt) {
List<ExtensionInfo> extensionInfos = Lists.newArrayList();
for (Method method : businessExt.getClass().getDeclaredMethods()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
package org.hiforce.lattice.maven.builder;

import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.model.Dependency;
import org.hifforce.lattice.model.ability.IBusinessExt;
import org.hifforce.lattice.model.business.IProduct;
import org.hifforce.lattice.model.register.ProductSpec;
import org.hiforce.lattice.maven.LatticeBuildPlugin;
import org.hiforce.lattice.maven.model.DependencyInfo;
import org.hiforce.lattice.maven.model.ProductInfo;
import org.hiforce.lattice.maven.model.RealizationInfo;
import org.hiforce.lattice.runtime.ability.register.TemplateRegister;

import java.io.File;
import java.net.URI;
import java.security.CodeSource;
import java.security.ProtectionDomain;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -81,27 +75,7 @@ private ProductInfo buildProductInfo(ProductSpec spec) {
} catch (Exception ex) {
getLog().error(ex.getMessage(), ex);
}


try {
ProtectionDomain protectionDomain = spec.getProductClass().getProtectionDomain();
CodeSource codeSource = protectionDomain.getCodeSource();
URI location = (codeSource != null) ? codeSource.getLocation().toURI() : null;
String path = (location != null) ? location.getSchemeSpecificPart() : null;

File file = new File(path);
DependencyInfo dependency = dependencies.stream()
.filter(p -> StringUtils.equals(file.getName(),
String.format("%s-%s.jar", p.getArtifactId(), p.getVersion())))
.findFirst()
.map(p -> DependencyInfo.of(p.getGroupId(), p.getArtifactId(), p.getVersion()))
.orElse(null);
if (null != dependency) {
info.setDependency(dependency);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
info.setDependency(getDependencyInfo(spec.getProductClass()));
return info;
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
package org.hiforce.lattice.maven.builder;

import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.model.Dependency;
import org.hifforce.lattice.model.ability.IBusinessExt;
import org.hifforce.lattice.model.business.IUseCase;
import org.hifforce.lattice.model.register.UseCaseSpec;
import org.hiforce.lattice.maven.LatticeBuildPlugin;
import org.hiforce.lattice.maven.model.DependencyInfo;
import org.hiforce.lattice.maven.model.RealizationInfo;
import org.hiforce.lattice.maven.model.UseCaseInfo;
import org.hiforce.lattice.runtime.ability.register.AbilityRegister;
import org.hiforce.lattice.runtime.ability.register.TemplateRegister;

import java.io.File;
import java.net.URI;
import java.security.CodeSource;
import java.security.ProtectionDomain;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -91,26 +85,7 @@ private UseCaseInfo buildUseCaseInfo(UseCaseSpec useCaseSpec) {
getLog().error(ex.getMessage(), ex);
}


try {
ProtectionDomain protectionDomain = useCaseSpec.getUseCaseClass().getProtectionDomain();
CodeSource codeSource = protectionDomain.getCodeSource();
URI location = (codeSource != null) ? codeSource.getLocation().toURI() : null;
String path = (location != null) ? location.getSchemeSpecificPart() : null;

File file = new File(path);
DependencyInfo dependency = dependencies.stream()
.filter(p -> StringUtils.equals(file.getName(),
String.format("%s-%s.jar", p.getArtifactId(), p.getVersion())))
.findFirst()
.map(p -> DependencyInfo.of(p.getGroupId(), p.getArtifactId(), p.getVersion()))
.orElse(null);
if (null != dependency) {
info.setDependency(dependency);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
info.setDependency(getDependencyInfo(useCaseSpec.getUseCaseClass()));
return info;
}

Expand Down
2 changes: 1 addition & 1 deletion lattice-tools/lattice-maven-build/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lattice-tools</artifactId>
<groupId>org.hiforce.lattice</groupId>
<version>1.0.9</version>
<version>1.0.9.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
Expand Down
2 changes: 1 addition & 1 deletion lattice-tools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lattice</artifactId>
<groupId>org.hiforce.lattice</groupId>
<version>1.0.9</version>
<version>1.0.9.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
<url>https://github.com/hiforce/lattice</url>
<inceptionYear>2022</inceptionYear>

<version>1.0.9</version>
<version>1.0.9.1</version>
<properties>
<version.lattice>1.0.9</version.lattice>
<version.lattice>1.0.9.1</version.lattice>
<version.spring>5.3.23</version.spring>
<version.spring.boot>2.7.4</version.spring.boot>
<springext-plugin-version>1.2</springext-plugin-version>
Expand Down

0 comments on commit d704db6

Please sign in to comment.