feat:独立spring-brick仓库

V0.5.x
xiwa 2024-01-06 22:43:18 +08:00
parent 7a4c5e7390
commit 69df507ae3
48 changed files with 1 additions and 4039 deletions

View File

@ -15,7 +15,6 @@
<modules>
<module>iot-plugin-core</module>
<module>iot-plugin-main</module>
<module>spring-brick-maven-packager</module>
</modules>
</project>

View File

@ -1,101 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>iot-plugin</artifactId>
<groupId>cc.iotkit</groupId>
<version>0.5.1-SNAPSHOT</version>
</parent>
<groupId>com.gitee.starblues</groupId>
<version>3.1.3</version>
<artifactId>spring-brick-maven-packager</artifactId>
<packaging>jar</packaging>
<description>用于打包主程序/插件模块</description>
<properties>
<java.version>8</java.version>
<maven.version>3.0.0</maven.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
<maven-plugin-api.version>3.8.4</maven-plugin-api.version>
<maven-plugin-annotations.version>3.6.2</maven-plugin-annotations.version>
<maven-common-artifact-filters.version>3.2.0</maven-common-artifact-filters.version>
<commons-compress.version>1.21</commons-compress.version>
<commons-io.version>2.11.0</commons-io.version>
<lombok.version>1.18.20</lombok.version>
<junit.version>3.8.1</junit.version>
<maven-plugin-plugin.version>3.6.0</maven-plugin-plugin.version>
</properties>
<dependencies>
<!-- common -->
<dependency>
<groupId>com.gitee.starblues</groupId>
<artifactId>spring-brick-common</artifactId>
<version>${spring-brick.version}</version>
</dependency>
<!-- maven api -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>${maven-plugin-api.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>${maven-plugin-annotations.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-common-artifact-filters</artifactId>
<version>${maven-common-artifact-filters.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>${commons-compress.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>${maven-plugin-plugin.version}</version>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,108 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack;
import com.gitee.starblues.plugin.pack.filter.Exclude;
import com.gitee.starblues.plugin.pack.filter.ExcludeFilter;
import com.gitee.starblues.plugin.pack.filter.Include;
import com.gitee.starblues.plugin.pack.filter.IncludeFilter;
import com.gitee.starblues.plugin.pack.utils.CommonUtils;
import com.gitee.starblues.utils.ObjectUtils;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter;
import org.apache.maven.shared.artifact.filter.collection.FilterArtifacts;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
/**
* mojo
*
* @author starBlues
* @since 3.0.0
* @version 3.0.0
*/
@EqualsAndHashCode(callSuper = true)
@Data
public abstract class AbstractDependencyFilterMojo extends AbstractMojo {
@Parameter(property = "spring-brick-packager.includes")
private List<Include> includes;
@Parameter(property = "spring-brick-packager.excludes")
private List<Exclude> excludes;
protected final Set<Artifact> filterDependencies(Set<Artifact> dependencies, FilterArtifacts filters)
throws MojoExecutionException {
try {
Set<Artifact> filtered = new LinkedHashSet<>(dependencies);
filtered.retainAll(filters.filter(dependencies));
return filtered;
}
catch (ArtifactFilterException ex) {
throw new MojoExecutionException(ex.getMessage(), ex);
}
}
protected final FilterArtifacts getFilters(ArtifactsFilter... additionalFilters) {
FilterArtifacts filters = new FilterArtifacts();
for (ArtifactsFilter additionalFilter : additionalFilters) {
filters.addFilter(additionalFilter);
}
if (!ObjectUtils.isEmpty(includes)) {
filters.addFilter(new IncludeFilter(this.includes));
}
if(ObjectUtils.isEmpty(excludes)){
excludes = new ArrayList<>();
}
// 添加主框架排除
addPluginFrameworkExclude();
// 添加spring web 环境排除
addSpringWebEnvExclude();
filters.addFilter(new ExcludeFilter(this.excludes));
return filters;
}
private void addPluginFrameworkExclude(){
excludes.add(CommonUtils.getPluginFrameworkExclude());
}
private void addSpringWebEnvExclude(){
excludes.add(Exclude.get("org.springframework.boot", "spring-boot-starter-web"));
excludes.add(Exclude.get("org.springframework.boot", "spring-boot-starter-tomcat"));
excludes.add(Exclude.get("org.springframework.boot", "spring-boot-starter-json"));
excludes.add(Exclude.get("org.springframework", "spring-webmvc"));
excludes.add(Exclude.get("org.springframework", "spring-web"));
// jackson
excludes.add(Exclude.get("com.fasterxml.jackson.core", "jackson-core"));
excludes.add(Exclude.get("com.fasterxml.jackson.core", "jackson-databind"));
excludes.add(Exclude.get("com.fasterxml.jackson.core", "jackson-annotations"));
excludes.add(Exclude.get("com.fasterxml.jackson.module", "jackson-module-parameter-names"));
}
}

View File

@ -1,93 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import java.io.File;
import java.util.Set;
/**
* mojo
*
* @author starBlues
* @since 3.0.0
* @version 3.1.1
*/
@EqualsAndHashCode(callSuper = true)
@Data
public abstract class AbstractPackagerMojo extends AbstractDependencyFilterMojo{
@Parameter(defaultValue = "${project}", readonly = true, required = true)
private MavenProject project;
@Parameter(defaultValue = "${project.build.directory}", required = true)
private File outputDirectory;
@Parameter(property = "spring-brick-packager.mode", defaultValue = "dev", required = true)
private String mode;
@Parameter(property = "spring-brick-packager.skip", defaultValue = "false")
private boolean skip;
@Parameter
private String classifier;
@Parameter(property = "spring-brick-packager.pluginInfo")
private PluginInfo pluginInfo;
@Parameter(property = "spring-brick-packager.loadMainResourcePattern", required = false)
private LoadMainResourcePattern loadMainResourcePattern;
@Parameter(property = "spring-brick-packager.includeSystemScope", defaultValue = "true", required = false)
private Boolean includeSystemScope;
@Override
public final void execute() throws MojoExecutionException, MojoFailureException {
if(Constant.isPom(this.getProject().getPackaging())){
getLog().debug("repackage goal could not be applied to pom project.");
return;
}
if (this.skip) {
getLog().debug("skipping plugin package.");
return;
}
pack();
}
/**
*
* @throws MojoExecutionException MojoExecutionException
* @throws MojoFailureException MojoFailureException
*/
protected abstract void pack() throws MojoExecutionException, MojoFailureException;
public final Set<Artifact> getFilterDependencies() throws MojoExecutionException {
Set<Artifact> artifacts = project.getArtifacts();
return filterDependencies(artifacts, getFilters());
}
public final Set<Artifact> getSourceDependencies() throws MojoExecutionException {
return project.getArtifacts();
}
}

View File

@ -1,380 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack;
import com.gitee.starblues.common.*;
import com.gitee.starblues.plugin.pack.utils.CommonUtils;
import com.gitee.starblues.utils.FilesUtils;
import com.gitee.starblues.utils.ObjectUtils;
import lombok.Getter;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.*;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
import static com.gitee.starblues.common.PackageStructure.*;
import static com.gitee.starblues.common.PluginDescriptorKey.*;
/**
*
*
* @author starBlues
* @since 3.0.0
* @version 3.1.1
*/
public class BasicRepackager implements Repackager{
@Getter
private String rootDir;
private String relativeManifestPath;
private String relativePluginMetaPath;
private String relativeResourcesDefinePath;
protected File resourcesDefineFile;
protected final RepackageMojo repackageMojo;
protected JarFile sourceJarFile;
public BasicRepackager(RepackageMojo repackageMojo) {
this.repackageMojo = repackageMojo;
}
@Override
public void repackage() throws MojoExecutionException, MojoFailureException {
sourceJarFile = CommonUtils.getSourceJarFile(repackageMojo.getProject());
checkPluginInfo();
rootDir = createRootDir();
relativeManifestPath = getRelativeManifestPath();
relativePluginMetaPath = getRelativePluginMetaPath();
relativeResourcesDefinePath = getRelativeResourcesDefinePath();
try {
Manifest manifest = getManifest();
writeManifest(manifest);
} catch (Exception e) {
repackageMojo.getLog().error(e.getMessage(), e);
throw new MojoFailureException(e);
} finally {
IOUtils.closeQuietly(sourceJarFile);
}
}
private void checkPluginInfo() throws MojoExecutionException {
PluginInfo pluginInfo = repackageMojo.getPluginInfo();
if(pluginInfo == null){
throw new MojoExecutionException("configuration.pluginInfo config cannot be empty");
}
if(ObjectUtils.isEmpty(pluginInfo.getId())){
throw new MojoExecutionException("configuration.pluginInfo.id config cannot be empty");
} else {
String id = pluginInfo.getId();
String illegal = PackageStructure.getIllegal(id);
if(illegal != null){
throw new MojoExecutionException("configuration.pluginInfo.id config can't contain: " + illegal);
}
}
if(ObjectUtils.isEmpty(pluginInfo.getBootstrapClass())){
throw new MojoExecutionException("configuration.pluginInfo.bootstrapClass config cannot be empty");
}
if(ObjectUtils.isEmpty(pluginInfo.getVersion())){
throw new MojoExecutionException("configuration.pluginInfo.version config cannot be empty");
} else {
String version = pluginInfo.getVersion();
String illegal = PackageStructure.getIllegal(version);
if(illegal != null){
throw new MojoExecutionException("configuration.pluginInfo.version config can't contain: " + illegal);
}
}
}
protected String getRelativeManifestPath(){
return MANIFEST;
}
protected String getRelativeResourcesDefinePath(){
return RESOURCES_DEFINE_NAME;
}
protected String getRelativePluginMetaPath(){
return PLUGIN_META_NAME;
}
protected String createRootDir() throws MojoFailureException {
String rootDirPath = getBasicRootDir();
File rootDir = new File(rootDirPath);
CommonUtils.deleteFile(rootDir);
if(rootDir.mkdir()){
return rootDirPath;
}
throw new MojoFailureException("Failed to create the plugin root directory. " + rootDirPath);
}
protected String getBasicRootDir(){
File outputDirectory = repackageMojo.getOutputDirectory();
return FilesUtils.joiningFilePath(outputDirectory.getPath(), PackageStructure.META_INF_NAME);
}
protected void writeManifest(Manifest manifest) throws Exception {
String manifestPath = FilesUtils.joiningFilePath(rootDir, resolvePath(this.relativeManifestPath));
File file = new File(manifestPath);
FileOutputStream outputStream = null;
try {
FileUtils.forceMkdirParent(file);
if(file.createNewFile()){
outputStream = new FileOutputStream(file, false);
manifest.write(outputStream);
}
} finally {
if(outputStream != null){
try {
outputStream.close();
} catch (IOException e) {
repackageMojo.getLog().error(e.getMessage(), e);
}
}
}
}
protected Manifest getManifest() throws Exception{
Manifest manifest = null;
if(sourceJarFile != null){
manifest = sourceJarFile.getManifest();
} else {
manifest = new Manifest();
}
Attributes attributes = manifest.getMainAttributes();
attributes.putValue(ManifestKey.MANIFEST_VERSION, ManifestKey.MANIFEST_VERSION_1_0);
attributes.putValue(ManifestKey.BUILD_TIME, CommonUtils.getDateTime());
attributes.putValue(ManifestKey.PLUGIN_META_PATH, getPluginMetaInfoPath());
attributes.putValue(ManifestKey.PLUGIN_PACKAGE_TYPE, PackageType.PLUGIN_PACKAGE_TYPE_DEV);
// 增加jar包title和version属性
MavenProject mavenProject = this.repackageMojo.getProject();
attributes.putValue(ManifestKey.IMPLEMENTATION_TITLE, mavenProject.getArtifactId());
attributes.putValue(ManifestKey.IMPLEMENTATION_VERSION, mavenProject.getVersion());
return manifest;
}
/**
*
* @return
* @throws Exception Exception
*/
protected String getPluginMetaInfoPath() throws Exception {
Properties pluginMetaInfo = createPluginMetaInfo();
return writePluginMetaInfo(pluginMetaInfo);
}
/**
*
* @return Properties
* @throws Exception Exception
*/
protected Properties createPluginMetaInfo() throws Exception {
Properties properties = new Properties();
PluginInfo pluginInfo = repackageMojo.getPluginInfo();
properties.put(PLUGIN_ID, pluginInfo.getId());
properties.put(PLUGIN_BOOTSTRAP_CLASS, pluginInfo.getBootstrapClass());
properties.put(PLUGIN_VERSION, pluginInfo.getVersion());
properties.put(PLUGIN_PATH, getPluginPath());
String resourcesDefineFilePath = writeResourcesDefineFile(getResourcesDefineContent());
if(!ObjectUtils.isEmpty(resourcesDefineFilePath)){
properties.put(PLUGIN_RESOURCES_CONFIG, resourcesDefineFilePath);
}
String configFileName = pluginInfo.getConfigFileName();
if(!ObjectUtils.isEmpty(configFileName)){
properties.put(PLUGIN_CONFIG_FILE_NAME, configFileName);
}
String configFileLocation = pluginInfo.getConfigFileLocation();
if(!ObjectUtils.isEmpty(configFileLocation)){
properties.put(PLUGIN_CONFIG_FILE_LOCATION, configFileLocation);
}
String args = pluginInfo.getArgs();
if(!ObjectUtils.isEmpty(args)){
properties.put(PLUGIN_ARGS, args);
}
String provider = pluginInfo.getProvider();
if(!ObjectUtils.isEmpty(provider)){
properties.put(PLUGIN_PROVIDER, provider);
}
String requires = pluginInfo.getRequires();
if(!ObjectUtils.isEmpty(requires)){
properties.put(PLUGIN_REQUIRES, requires);
}
String dependencyPlugins = getDependencyPlugin(pluginInfo);
if(!ObjectUtils.isEmpty(dependencyPlugins)){
properties.put(PLUGIN_DEPENDENCIES, dependencyPlugins);
}
String description = pluginInfo.getDescription();
if(!ObjectUtils.isEmpty(description)){
properties.put(PLUGIN_DESCRIPTION, description);
}
String license = pluginInfo.getLicense();
if(!ObjectUtils.isEmpty(license)){
properties.put(PLUGIN_LICENSE, license);
}
return properties;
}
protected String getDependencyPlugin(PluginInfo pluginInfo){
List<DependencyPlugin> dependencyPlugins = pluginInfo.getDependencyPlugins();
return AbstractDependencyPlugin.toStr(dependencyPlugins);
}
/**
*
* @param properties properties
* @return String
* @throws IOException IOException
*/
protected String writePluginMetaInfo(Properties properties) throws Exception {
File pluginMetaFile = createPluginMetaFile();
try (OutputStreamWriter writer = new OutputStreamWriter(
Files.newOutputStream(pluginMetaFile.toPath()), StandardCharsets.UTF_8)){
properties.store(writer, Constant.PLUGIN_METE_COMMENTS);
return pluginMetaFile.getPath();
}
}
/**
*
* @return File
* @throws IOException
*/
protected File createPluginMetaFile() throws IOException {
String path = FilesUtils.joiningFilePath(rootDir, resolvePath(relativePluginMetaPath));
return FilesUtils.createFile(path);
}
/**
*
* @return
*/
protected String getPluginPath(){
return repackageMojo.getProject().getBuild().getOutputDirectory();
}
protected String writeResourcesDefineFile(String resourcesDefineContent) throws Exception{
resourcesDefineFile = createResourcesDefineFile();
FileUtils.write(resourcesDefineFile, resourcesDefineContent, CHARSET_NAME, true);
return resourcesDefineFile.getPath();
}
protected File createResourcesDefineFile() throws IOException {
String path = FilesUtils.joiningFilePath(rootDir, resolvePath(relativeResourcesDefinePath));
return FilesUtils.createFile(path);
}
protected String getResourcesDefineContent() throws Exception {
String dependenciesIndex = getDependenciesIndex();
String loadMainResources = getLoadMainResources();
boolean indexIsEmpty = ObjectUtils.isEmpty(dependenciesIndex);
boolean resourceIsEmpty = ObjectUtils.isEmpty(loadMainResources);
if(!indexIsEmpty && !resourceIsEmpty){
return dependenciesIndex + "\n" + loadMainResources;
} else if(!indexIsEmpty){
return dependenciesIndex;
} else if(!resourceIsEmpty){
return loadMainResources;
} else {
return "";
}
}
protected String getDependenciesIndex() throws Exception {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(RESOURCES_DEFINE_DEPENDENCIES).append("\n");
Set<String> libIndex = getDependenciesIndexSet();
for (String index : libIndex) {
stringBuilder.append(index).append("\n");
}
return stringBuilder.toString();
}
protected String getLoadMainResources(){
LoadMainResourcePattern loadMainResourcePattern = repackageMojo.getLoadMainResourcePattern();
if(loadMainResourcePattern == null){
return null;
}
String[] includes = loadMainResourcePattern.getIncludes();
String[] excludes = loadMainResourcePattern.getExcludes();
StringBuilder stringBuilder = new StringBuilder();
addLoadMainResources(stringBuilder, RESOURCES_DEFINE_LOAD_MAIN_INCLUDES, includes);
addLoadMainResources(stringBuilder, RESOURCES_DEFINE_LOAD_MAIN_EXCLUDES, excludes);
return stringBuilder.toString();
}
protected Set<String> getDependenciesIndexSet() throws Exception {
Set<Artifact> dependencies = repackageMojo.getFilterDependencies();
Set<String> libPaths = new LinkedHashSet<>(dependencies.size());
for (Artifact artifact : dependencies) {
if(filterArtifact(artifact)){
continue;
}
libPaths.add(getLibIndex(artifact));
}
return libPaths;
}
protected String getLibIndex(Artifact artifact){
return artifact.getFile().getPath() + repackageMojo.resolveLoadToMain(artifact);
}
private void addLoadMainResources(StringBuilder stringBuilder, String header, String[] patterns){
if(ObjectUtils.isEmpty(patterns)){
return;
}
Set<String> patternSet = new LinkedHashSet<>(Arrays.asList(patterns));
stringBuilder.append(header).append("\n");
for (String patternStr : patternSet) {
if(ObjectUtils.isEmpty(patternStr)){
continue;
}
stringBuilder.append(resolvePattern(patternStr)).append("\n");
}
}
protected String resolvePattern(String patternStr){
return patternStr.replace(".", "/");
}
/**
* Artifact
* @param artifact Artifact
* @return true
*/
protected boolean filterArtifact(Artifact artifact){
return Constant.filterMainTypeArtifact(artifact) ||
Constant.filterArtifact(artifact, repackageMojo.getIncludeSystemScope());
}
}

View File

@ -1,85 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack;
import org.apache.maven.artifact.Artifact;
/**
*
*
* @author starBlues
* @since 3.0.0
* @version 3.0.0
*/
public class Constant {
public static final String PACKAGING_POM = "pom";
public static final String SCOPE_PROVIDED = "provided";
public static final String SCOPE_COMPILE = "compile";
public static final String SCOPE_SYSTEM = "system";
public static final String SCOPE_TEST = "test";
public static final String MAVEN_POM_TYPE = "pom";
public static final String MAVEN_MAIN_TYPE = "main";
public static final String MODE_MAIN = "main";
public static final String MODE_DEV = "dev";
public static final String MODE_PROD = "prod";
public static final String PLUGIN_METE_COMMENTS = "plugin meta configuration";
/**
*
*/
public static final String DEVELOPMENT_MODE_METHOD_NAME = "developmentMode";
public static boolean isPom(String packageType){
return PACKAGING_POM.equalsIgnoreCase(packageType);
}
public static boolean filterArtifact(Artifact artifact, Boolean includeSystemScope){
boolean scopeFilter = Constant.scopeFilter(artifact.getScope());
if(scopeFilter){
return true;
}
if(Constant.isSystemScope(artifact.getScope())){
return includeSystemScope == null || !includeSystemScope;
}
return Constant.filterPomTypeArtifact(artifact);
}
public static boolean filterMainTypeArtifact(Artifact artifact){
// 配置了为main的依赖, 则对其过滤
return MAVEN_MAIN_TYPE.equalsIgnoreCase(artifact.getType());
}
public static boolean filterPomTypeArtifact(Artifact artifact){
return MAVEN_POM_TYPE.equalsIgnoreCase(artifact.getType());
}
public static boolean scopeFilter(String scope){
return SCOPE_PROVIDED.equalsIgnoreCase(scope)
|| SCOPE_TEST.equalsIgnoreCase(scope);
}
public static boolean isSystemScope(String scope){
return SCOPE_SYSTEM.equalsIgnoreCase(scope);
}
}

View File

@ -1,38 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack;
import lombok.Data;
import org.apache.maven.plugins.annotations.Parameter;
/**
* Bean
*
* @author starBlues
* @since 3.0.0
* @version 3.0.0
*/
@Data
public class Dependency {
@Parameter(required = true)
private String groupId;
@Parameter(required = true)
private String artifactId;
}

View File

@ -1,73 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack;
import com.gitee.starblues.common.AbstractDependencyPlugin;
import org.apache.maven.plugins.annotations.Parameter;
/**
*
*
* @author starBlues
* @since 3.0.0
* @version 3.0.0
*/
public class DependencyPlugin extends AbstractDependencyPlugin {
@Parameter(required = true)
private String id;
@Parameter(required = true)
private String version;
@Parameter(required = false, defaultValue = "true")
private Boolean optional = false;
@Override
public String getId() {
return id;
}
@Override
public String getVersion() {
return version;
}
@Override
public Boolean getOptional() {
if(optional == null){
return false;
}
return optional;
}
@Override
public void setId(String id) {
this.id = id;
}
@Override
public void setVersion(String version) {
this.version = version;
}
@Override
public void setOptional(Boolean optional) {
this.optional = optional;
}
}

View File

@ -1,38 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack;
import lombok.Data;
import org.apache.maven.plugins.annotations.Parameter;
/**
*
*
* @author starBlues
* @since 3.0.0
* @version 3.0.0
*/
@Data
public class LoadMainResourcePattern {
@Parameter(name = "includes")
private String[] includes;
@Parameter(name = "excludes")
private String[] excludes;
}

View File

@ -1,35 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack;
import lombok.Data;
import java.util.List;
/**
*
*
* @author starBlues
* @since 3.0.0
* @version 3.0.0
*/
@Data
public class LoadToMain {
private List<Dependency> dependencies;
}

View File

@ -1,92 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack;
import lombok.Data;
import org.apache.maven.plugins.annotations.Parameter;
import java.util.List;
/**
*
*
* @author starBlues
* @since 3.0.0
* @version 3.0.0
*/
@Data
public class PluginInfo {
/**
* id
*/
@Parameter(required = true)
private String id;
/**
*
*/
@Parameter(required = true)
private String bootstrapClass;
/**
*
*/
@Parameter(required = true)
private String version;
/**
*
*/
private String configFileName;
/**
* , target/classes
*/
private String configFileLocation;
/**
*
*/
private String args;
/**
*
*/
private String description;
/**
*
*/
private String provider;
/**
*
*/
private String requires;
/**
* license
*/
private String license;
/**
*
*/
private List<DependencyPlugin> dependencyPlugins;
}

View File

@ -1,133 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack;
import com.gitee.starblues.common.Constants;
import com.gitee.starblues.plugin.pack.dev.DevConfig;
import com.gitee.starblues.plugin.pack.dev.DevRepackager;
import com.gitee.starblues.plugin.pack.encrypt.*;
import com.gitee.starblues.plugin.pack.main.MainConfig;
import com.gitee.starblues.plugin.pack.main.MainRepackager;
import com.gitee.starblues.plugin.pack.prod.ProdConfig;
import com.gitee.starblues.plugin.pack.prod.ProdRepackager;
import com.gitee.starblues.plugin.pack.utils.CommonUtils;
import com.gitee.starblues.utils.ObjectUtils;
import lombok.Getter;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
/**
* mojo
*
* @author starBlues
* @since 3.0.0
* @version 3.1.1
*/
@Mojo(name = "repackage", defaultPhase = LifecyclePhase.PACKAGE, requiresProject = true, threadSafe = true,
requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME,
requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME)
@Getter
public class RepackageMojo extends AbstractPackagerMojo {
@Parameter(property = "spring-brick-packager.devConfig")
private DevConfig devConfig;
@Parameter(property = "spring-brick-packager.prodConfig")
private ProdConfig prodConfig;
@Parameter(property = "spring-brick-packager.mainConfig")
private MainConfig mainConfig;
@Parameter(property = "spring-brick-packager.mainLoad")
private LoadToMain loadToMain;
@Parameter(property = "spring-brick-packager.encryptConfig")
private EncryptConfig encryptConfig;
private final Set<String> loadToMainSet = new LinkedHashSet<>();
@Override
protected void pack() throws MojoExecutionException, MojoFailureException {
initLoadToMainSet();
String mode = getMode();
try {
encrypt();
} catch (Exception e) {
throw new MojoExecutionException("encrypt failed: " + e.getMessage());
}
if(Constant.MODE_PROD.equalsIgnoreCase(mode)){
new ProdRepackager(this).repackage();
} else if(Constant.MODE_DEV.equalsIgnoreCase(mode)){
new DevRepackager(this).repackage();
} else if(Constant.MODE_MAIN.equalsIgnoreCase(mode)){
new MainRepackager(this).repackage();
} else {
throw new MojoExecutionException(mode +" model not supported, mode support : "
+ Constant.MODE_DEV + "/" + Constant.MODE_PROD);
}
}
public String resolveLoadToMain(Artifact artifact){
if(artifact == null){
return "";
}
if(loadToMainSet.contains(artifact.getGroupId() + artifact.getArtifactId())){
return Constants.LOAD_TO_MAIN_SIGN;
}
return "";
}
private void initLoadToMainSet(){
if(loadToMain == null){
return;
}
List<Dependency> dependencies = loadToMain.getDependencies();
if(ObjectUtils.isEmpty(dependencies)){
return;
}
for (Dependency dependency : dependencies) {
loadToMainSet.add(dependency.getGroupId() + dependency.getArtifactId());
}
}
/**
*
* @throws Exception
*/
private void encrypt() throws Exception {
if(encryptConfig == null){
return;
}
EncryptPlugin encryptPlugin = new EncryptPluginFactory();
PluginInfo pluginInfo = encryptPlugin.encrypt(encryptConfig, getPluginInfo());
if(pluginInfo != null){
setPluginInfo(pluginInfo);
}
}
}

View File

@ -1,39 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
/**
*
*
* @author starBlues
* @since 3.0.0
* @version 3.0.0
*/
public interface Repackager {
/**
*
* @throws MojoExecutionException MojoExecutionException
* @throws MojoFailureException MojoFailureException
*/
void repackage() throws MojoExecutionException, MojoFailureException;
}

View File

@ -1,41 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack.dev;
import lombok.Data;
import org.apache.maven.plugins.annotations.Parameter;
/**
* Bean
*
* @author starBlues
* @since 3.0.0
* @version 3.0.0
*/
@Data
public class Dependency {
@Parameter(required = true)
private String groupId;
@Parameter(required = true)
private String artifactId;
@Parameter(required = true)
private String classesPath;
}

View File

@ -1,44 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack.dev;
import lombok.Data;
import java.util.List;
/**
*
*
* @author starBlues
* @since 3.0.0
* @version 3.0.0
*/
@Data
public class DevConfig {
/**
*
* target->classes, 便
*/
private List<Dependency> moduleDependencies;
/**
* jar
*/
private List<String> localJars;
}

View File

@ -1,102 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack.dev;
import com.gitee.starblues.plugin.pack.BasicRepackager;
import com.gitee.starblues.plugin.pack.Constant;
import com.gitee.starblues.plugin.pack.RepackageMojo;
import com.gitee.starblues.plugin.pack.utils.CommonUtils;
import com.gitee.starblues.utils.FilesUtils;
import com.gitee.starblues.utils.ObjectUtils;
import lombok.Getter;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import java.util.*;
/**
*
*
* @author starBlues
* @since 3.0.0
* @version 3.0.0
*/
public class DevRepackager extends BasicRepackager {
@Getter
private Map<String, Dependency> moduleDependencies = Collections.emptyMap();
public DevRepackager(RepackageMojo repackageMojo) {
super(repackageMojo);
}
@Override
protected Set<String> getDependenciesIndexSet() throws Exception {
DevConfig devConfig = repackageMojo.getDevConfig();
if(devConfig == null){
return super.getDependenciesIndexSet();
}
moduleDependencies = getModuleDependencies(devConfig);
Set<String> dependenciesIndexSet = super.getDependenciesIndexSet();
for (Dependency dependency : moduleDependencies.values()) {
dependenciesIndexSet.add(dependency.getClassesPath());
}
List<String> localJars = devConfig.getLocalJars();
if(!ObjectUtils.isEmpty(localJars)){
dependenciesIndexSet.addAll(localJars);
}
return dependenciesIndexSet;
}
@Override
protected boolean filterArtifact(Artifact artifact) {
if(super.filterArtifact(artifact)){
return true;
}
String moduleDependencyKey = getModuleDependencyKey(artifact.getGroupId(), artifact.getArtifactId());
Dependency dependency = moduleDependencies.get(moduleDependencyKey);
return dependency != null && !ObjectUtils.isEmpty(dependency.getClassesPath());
}
protected Map<String, Dependency> getModuleDependencies(DevConfig devConfig) {
if(devConfig == null){
return Collections.emptyMap();
}
List<Dependency> moduleDependencies = devConfig.getModuleDependencies();
if(ObjectUtils.isEmpty(moduleDependencies)){
return Collections.emptyMap();
}
Map<String, Dependency> moduleDependenciesMap = new HashMap<>();
for (Dependency dependency : moduleDependencies) {
String moduleDependencyKey = getModuleDependencyKey(dependency.getGroupId(),
dependency.getArtifactId());
if(moduleDependencyKey == null){
continue;
}
moduleDependenciesMap.put(moduleDependencyKey, dependency);
}
return moduleDependenciesMap;
}
protected String getModuleDependencyKey(String groupId, String artifactId){
if(ObjectUtils.isEmpty(groupId) || ObjectUtils.isEmpty(artifactId)){
return null;
}
return groupId + artifactId;
}
}

View File

@ -1,33 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack.encrypt;
import lombok.Data;
/**
* aes
*
* @author starBlues
* @since 3.0.1
* @version 3.0.1
*/
@Data
public class AesConfig {
private String secretKey;
}

View File

@ -1,43 +0,0 @@
package com.gitee.starblues.plugin.pack.encrypt;
import com.gitee.starblues.common.cipher.AbstractPluginCipher;
import com.gitee.starblues.common.cipher.AesPluginCipher;
import com.gitee.starblues.plugin.pack.PluginInfo;
import com.gitee.starblues.utils.ObjectUtils;
import org.apache.maven.plugin.MojoExecutionException;
import java.util.HashMap;
import java.util.Map;
/**
* rsa
*
* @author starBlues
* @since 3.0.1
* @version 3.0.1
*/
public class AesEncryptPlugin implements EncryptPlugin{
@Override
public PluginInfo encrypt(EncryptConfig encryptConfig, PluginInfo pluginInfo) throws Exception{
AesConfig aesConfig = encryptConfig.getAes();
if(aesConfig == null){
return null;
}
String secretKey = aesConfig.getSecretKey();
if(ObjectUtils.isEmpty(secretKey)){
throw new MojoExecutionException("encryptConfig.aes.secretKey can't be empty");
}
AbstractPluginCipher pluginCipher = new AesPluginCipher();
Map<String, Object> params = new HashMap<>();
params.put(AesPluginCipher.SECRET_KEY, secretKey);
pluginCipher.initParams(params);
String bootstrapClass = pluginInfo.getBootstrapClass();
String encrypt = pluginCipher.encrypt(bootstrapClass);
pluginInfo.setBootstrapClass(encrypt);
return pluginInfo;
}
}

View File

@ -1,41 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack.encrypt;
import lombok.Data;
/**
*
*
* @author starBlues
* @since 3.0.1
* @version 3.0.1
*/
@Data
public class EncryptConfig {
/**
* rsa
*/
private RsaConfig rsa;
/**
* aes
*/
private AesConfig aes;
}

View File

@ -1,40 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack.encrypt;
import com.gitee.starblues.plugin.pack.PluginInfo;
/**
*
*
* @author starBlues
* @since 3.0.1
* @version 3.0.1
*/
public interface EncryptPlugin {
/**
*
* @param pluginInfo
* @param encryptConfig
* @return
* @throws Exception
*/
PluginInfo encrypt(EncryptConfig encryptConfig, PluginInfo pluginInfo) throws Exception;
}

View File

@ -1,50 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack.encrypt;
import com.gitee.starblues.plugin.pack.PluginInfo;
import java.util.ArrayList;
import java.util.List;
/**
*
*
* @author starBlues
* @since 3.0.1
* @version 3.0.1
*/
public class EncryptPluginFactory implements EncryptPlugin {
private final List<EncryptPlugin> encryptPlugins = new ArrayList<>();
public EncryptPluginFactory(){
encryptPlugins.add(new AesEncryptPlugin());
encryptPlugins.add(new RsaEncryptPlugin());
}
@Override
public PluginInfo encrypt(EncryptConfig encryptConfig, PluginInfo pluginInfo) throws Exception{
for (EncryptPlugin encryptPlugin : encryptPlugins) {
PluginInfo encrypt = encryptPlugin.encrypt(encryptConfig, pluginInfo);
if(encrypt != null){
return encrypt;
}
}
return pluginInfo;
}
}

View File

@ -1,36 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack.encrypt;
import lombok.Data;
/**
* rsa
*
* @author starBlues
* @since 3.0.1
* @version 3.0.1
*/
@Data
public class RsaConfig {
/**
* rsa
*/
private String publicKey;
}

View File

@ -1,57 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack.encrypt;
import com.gitee.starblues.common.cipher.AbstractPluginCipher;
import com.gitee.starblues.common.cipher.RsaPluginCipher;
import com.gitee.starblues.plugin.pack.PluginInfo;
import com.gitee.starblues.utils.ObjectUtils;
import org.apache.maven.plugin.MojoExecutionException;
import java.util.HashMap;
import java.util.Map;
/**
* rsa
*
* @author starBlues
* @since 3.0.1
* @version 3.0.1
*/
public class RsaEncryptPlugin implements EncryptPlugin{
@Override
public PluginInfo encrypt(EncryptConfig encryptConfig, PluginInfo pluginInfo) throws Exception {
RsaConfig rsaConfig = encryptConfig.getRsa();
if(rsaConfig == null){
return null;
}
String publicKey = rsaConfig.getPublicKey();
if(ObjectUtils.isEmpty(publicKey)){
throw new MojoExecutionException("encryptConfig.rsa.publicKey can't be empty");
}
AbstractPluginCipher pluginCipher = new RsaPluginCipher();
Map<String, Object> params = new HashMap<>();
params.put(RsaPluginCipher.PUBLIC_KEY, publicKey);
pluginCipher.initParams(params);
String bootstrapClass = pluginInfo.getBootstrapClass();
pluginInfo.setBootstrapClass(pluginCipher.encrypt(bootstrapClass));
return pluginInfo;
}
}

View File

@ -1,75 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack.filter;
import com.gitee.starblues.utils.ObjectUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.shared.artifact.filter.collection.AbstractArtifactsFilter;
import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
/**
*
*
* @author starBlues
* @since 3.0.0
* @version 3.0.0
*/
public abstract class DependencyFilter extends AbstractArtifactsFilter {
private final List<? extends FilterableDependency> filters;
public DependencyFilter(List<? extends FilterableDependency> dependencies) {
this.filters = dependencies;
}
@Override
public Set<Artifact> filter(Set<Artifact> artifacts) throws ArtifactFilterException {
if(ObjectUtils.isEmpty(artifacts)){
return artifacts;
}
Set<Artifact> result = new LinkedHashSet<>();
for (Artifact artifact : artifacts) {
if (!filter(artifact)) {
result.add(artifact);
}
}
return result;
}
/**
*
* @param artifact artifact
* @return boolean
*/
protected abstract boolean filter(Artifact artifact);
protected final boolean equals(Artifact artifact, FilterableDependency dependency) {
if (!dependency.getGroupId().equals(artifact.getGroupId())) {
return false;
}
return dependency.getArtifactId().equals(artifact.getArtifactId());
}
protected final List<? extends FilterableDependency> getFilters() {
return this.filters;
}
}

View File

@ -1,35 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack.filter;
/**
*
*
* @author starBlues
* @since 3.0.0
* @version 3.0.0
*/
public class Exclude extends FilterableDependency{
public static Exclude get(String groupId, String artifactId){
Exclude exclude = new Exclude();
exclude.setGroupId(groupId);
exclude.setArtifactId(artifactId);
return exclude;
}
}

View File

@ -1,51 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack.filter;
import org.apache.maven.artifact.Artifact;
import java.util.Arrays;
import java.util.List;
/**
*
*
* @author starBlues
* @since 3.0.0
* @version 3.0.0
*/
public class ExcludeFilter extends DependencyFilter {
public ExcludeFilter(Exclude... excludes) {
this(Arrays.asList(excludes));
}
public ExcludeFilter(List<Exclude> excludes) {
super(excludes);
}
@Override
protected boolean filter(Artifact artifact) {
for (FilterableDependency dependency : getFilters()) {
if (equals(artifact, dependency)) {
return true;
}
}
return false;
}
}

View File

@ -1,38 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack.filter;
import lombok.Data;
import org.apache.maven.plugins.annotations.Parameter;
/**
* bean
*
* @author starBlues
* @since 3.0.0
* @version 3.0.0
*/
@Data
public abstract class FilterableDependency {
@Parameter(required = true)
private String groupId;
@Parameter(required = true)
private String artifactId;
}

View File

@ -1,27 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack.filter;
/**
*
*
* @author starBlues
* @since 3.0.0
* @version 3.0.0
*/
public class Include extends FilterableDependency{
}

View File

@ -1,46 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack.filter;
import org.apache.maven.artifact.Artifact;
import java.util.List;
/**
*
*
* @author starBlues
* @since 3.0.0
* @version 3.0.0
*/
public class IncludeFilter extends DependencyFilter {
public IncludeFilter(List<Include> includes) {
super(includes);
}
@Override
protected boolean filter(Artifact artifact) {
for (FilterableDependency dependency : getFilters()) {
if (equals(artifact, dependency)) {
return false;
}
}
return true;
}
}

View File

@ -1,138 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack.main;
import com.gitee.starblues.common.PackageType;
import com.gitee.starblues.plugin.pack.Constant;
import com.gitee.starblues.plugin.pack.RepackageMojo;
import com.gitee.starblues.plugin.pack.Repackager;
import com.gitee.starblues.plugin.pack.utils.CommonUtils;
import com.gitee.starblues.plugin.pack.utils.PackageJar;
import org.apache.commons.io.IOUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import java.io.File;
import java.util.List;
import java.util.Set;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
import static com.gitee.starblues.common.PackageStructure.*;
import static com.gitee.starblues.common.ManifestKey.*;
/**
* jar
*
* @author starBlues
* @since 3.0.0
* @version 3.1.1
*/
public class JarNestPackager implements Repackager {
protected final MainConfig mainConfig;
protected final RepackageMojo repackageMojo;
protected PackageJar packageJar;
private JarFile sourceJarFile;
public JarNestPackager(MainRepackager mainRepackager) {
this.mainConfig = mainRepackager.getMainConfig();
this.repackageMojo = mainRepackager.getRepackageMojo();
}
@Override
public void repackage() throws MojoExecutionException, MojoFailureException {
try {
sourceJarFile = CommonUtils.getSourceJarFile(repackageMojo.getProject());
packageJar = new PackageJar(mainConfig.getOutputDirectory(), mainConfig.getFileName());
writeClasses();
writeDependencies();
writeManifest();
} catch (Exception e) {
repackageMojo.getLog().error(e.getMessage(), e);
throw new MojoFailureException(e);
} finally {
IOUtils.closeQuietly(packageJar);
IOUtils.closeQuietly(sourceJarFile);
}
}
protected void writeManifest() throws Exception {
Manifest manifest = getManifest();
packageJar.putDirEntry(META_INF_NAME + SEPARATOR);
packageJar.write(PROD_MANIFEST_PATH, manifest::write);
}
protected Manifest getManifest() throws Exception{
Manifest manifest = null;
if(sourceJarFile != null){
manifest = sourceJarFile.getManifest();
} else {
manifest = new Manifest();
}
Attributes attributes = manifest.getMainAttributes();
attributes.putValue(MANIFEST_VERSION, MANIFEST_VERSION_1_0);
attributes.putValue(BUILD_TIME, CommonUtils.getDateTime());
attributes.putValue(START_CLASS, mainConfig.getMainClass());
attributes.putValue(MAIN_CLASS, MAIN_CLASS_VALUE);
attributes.putValue(MAIN_PACKAGE_TYPE, PackageType.MAIN_PACKAGE_TYPE_JAR);
attributes.putValue(DEVELOPMENT_MODE, mainConfig.getDevelopmentMode());
// 增加jar包title和version属性
MavenProject mavenProject = this.repackageMojo.getProject();
attributes.putValue(IMPLEMENTATION_TITLE, mavenProject.getArtifactId());
attributes.putValue(IMPLEMENTATION_VERSION, mavenProject.getVersion());
return manifest;
}
protected void writeClasses() throws Exception {
String buildDir = repackageMojo.getProject().getBuild().getOutputDirectory();
packageJar.copyDirToPackage(new File(buildDir), null);
}
protected void writeDependencies() throws Exception {
Set<Artifact> dependencies = repackageMojo.getSourceDependencies();
String libDirEntryName = createLibEntry();
for (Artifact artifact : dependencies) {
if(filterArtifact(artifact)){
continue;
}
if(CommonUtils.isPluginFrameworkLoader(artifact)){
// 本框架loader依赖
packageJar.copyZipToPackage(artifact.getFile());
} else {
packageJar.writeDependency(artifact.getFile(), libDirEntryName);
}
}
}
protected boolean filterArtifact(Artifact artifact) {
return Constant.filterArtifact(artifact, repackageMojo.getIncludeSystemScope());
}
protected String createLibEntry() throws Exception {
String libDirEntryName = PROD_LIB_PATH;
packageJar.putDirEntry(libDirEntryName);
return libDirEntryName;
}
}

View File

@ -1,146 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack.main;
import com.gitee.starblues.common.PackageStructure;
import com.gitee.starblues.common.PackageType;
import com.gitee.starblues.plugin.pack.utils.CommonUtils;
import com.gitee.starblues.utils.FilesUtils;
import com.gitee.starblues.utils.ObjectUtils;
import org.apache.commons.io.FileUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import java.io.File;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import static com.gitee.starblues.common.ManifestKey.*;
/**
* jar
*
* @author starBlues
* @since 3.0.0
* @version 3.0.2
*/
public class JarOuterPackager extends JarNestPackager {
private static final String LIB_INDEXES_SPLIT = " ";
private final Set<String> dependencyIndexNames = new LinkedHashSet<>();
public JarOuterPackager(MainRepackager mainRepackager) {
super(mainRepackager);
}
@Override
public void repackage() throws MojoExecutionException, MojoFailureException {
// 生成依赖文件夹
String rootDir = createRootDir();
mainConfig.setOutputDirectory(rootDir);
super.repackage();
}
@Override
protected void writeClasses() throws Exception {
String buildDir = repackageMojo.getProject().getBuild().getOutputDirectory();
packageJar.copyDirToPackage(new File(buildDir), null);
}
private String createRootDir() throws MojoFailureException{
String outputDirectory = mainConfig.getOutputDirectory();
String fileName = mainConfig.getFileName();
String rootDirPath = FilesUtils.joiningFilePath(outputDirectory, fileName);
File rootFile = new File(rootDirPath);
CommonUtils.deleteFile(rootFile);
if(rootFile.mkdirs()){
return rootDirPath;
} else {
throw new MojoFailureException("Create dir failure : " + rootDirPath);
}
}
@Override
protected Manifest getManifest() throws Exception {
Manifest manifest = new Manifest();
Attributes attributes = manifest.getMainAttributes();
attributes.putValue(MANIFEST_VERSION, MANIFEST_VERSION_1_0);
attributes.putValue(START_CLASS, mainConfig.getMainClass());
attributes.putValue(MAIN_CLASS, MAIN_CLASS_VALUE);
attributes.putValue(MAIN_PACKAGE_TYPE, PackageType.MAIN_PACKAGE_TYPE_JAR_OUTER);
attributes.putValue(MAIN_LIB_DIR, getLibPath());
attributes.putValue(DEVELOPMENT_MODE, mainConfig.getDevelopmentMode());
// 增加jar包title和version属性
MavenProject mavenProject = this.repackageMojo.getProject();
attributes.putValue(IMPLEMENTATION_TITLE, mavenProject.getArtifactId());
attributes.putValue(IMPLEMENTATION_VERSION, mavenProject.getVersion());
return manifest;
}
private String getLibIndexes() throws Exception {
if(dependencyIndexNames.isEmpty()){
return "";
}
StringBuilder libName = new StringBuilder();
for (String dependencyIndexName : dependencyIndexNames) {
libName.append(dependencyIndexName).append(LIB_INDEXES_SPLIT);
}
return libName.toString();
}
@Override
protected void writeDependencies() throws Exception {
Set<Artifact> dependencies = repackageMojo.getSourceDependencies();
for (Artifact artifact : dependencies) {
if(filterArtifact(artifact)){
continue;
}
if(CommonUtils.isPluginFrameworkLoader(artifact)){
// 本框架loader依赖
packageJar.copyZipToPackage(artifact.getFile());
} else {
File artifactFile = artifact.getFile();
String libPath = getLibPath();
if(FilesUtils.isRelativePath(libPath)){
libPath = FilesUtils.resolveRelativePath(mainConfig.getOutputDirectory(), getLibPath());
} else {
libPath = FilesUtils.joiningFilePath(mainConfig.getOutputDirectory(), libPath);
}
String targetFilePath = FilesUtils.joiningFilePath(libPath, artifactFile.getName());
FileUtils.copyFile(artifactFile, new File(targetFilePath));
dependencyIndexNames.add(artifactFile.getName());
}
}
}
private String getLibPath(){
String libDir = PackageStructure.LIB_NAME;
if(!ObjectUtils.isEmpty(mainConfig.getLibDir())){
libDir = mainConfig.getLibDir();
}
return libDir;
}
}

View File

@ -1,68 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack.main;
import lombok.Data;
import org.apache.maven.plugins.annotations.Parameter;
/**
*
*
* @author starBlues
* @since 3.0.0
* @version 3.0.0
*/
@Data
public class MainConfig {
/**
*
*/
@Parameter(required = true)
private String mainClass;
/**
* jar
* {@link com.gitee.starblues.common.PackageType#MAIN_PACKAGE_TYPE_JAR}
* {@link com.gitee.starblues.common.PackageType#MAIN_PACKAGE_TYPE_JAR_OUTER}
*/
private String packageType;
/**
* artifactId-version-repackage
*/
private String fileName;
/**
*
*/
private String libDir;
/**
* target
*/
private String outputDirectory;
/**
* :
* isolation: []
* coexist:
* simple:
*/
private String developmentMode;
}

View File

@ -1,136 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack.main;
import com.gitee.starblues.common.PackageType;
import com.gitee.starblues.plugin.pack.Constant;
import com.gitee.starblues.plugin.pack.RepackageMojo;
import com.gitee.starblues.plugin.pack.Repackager;
import com.gitee.starblues.plugin.pack.utils.CommonUtils;
import com.gitee.starblues.utils.ObjectUtils;
import com.gitee.starblues.utils.ReflectionUtils;
import lombok.Getter;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Set;
/**
*
*
* @author starBlues
* @since 3.0.0
* @version 3.1.1
*/
@Getter
public class MainRepackager implements Repackager {
private final RepackageMojo repackageMojo;
private final MainConfig mainConfig;
public MainRepackager(RepackageMojo repackageMojo) {
this.repackageMojo = repackageMojo;
this.mainConfig = repackageMojo.getMainConfig();
}
@Override
public void repackage() throws MojoExecutionException, MojoFailureException {
checkConfig();
setDevelopmentMode();
String packageType = mainConfig.getPackageType();
Repackager repackager = null;
if(PackageType.MAIN_PACKAGE_TYPE_JAR.equalsIgnoreCase(packageType)){
repackager = new JarNestPackager(this);
} else if(PackageType.MAIN_PACKAGE_TYPE_JAR_OUTER.equalsIgnoreCase(packageType)){
repackager = new JarOuterPackager(this);
} else {
throw new MojoFailureException("Not found packageType : " + packageType);
}
repackager.repackage();
}
private void checkConfig() throws MojoFailureException {
if(mainConfig == null){
throw new MojoFailureException("configuration.mainConfig config cannot be empty");
}
if(ObjectUtils.isEmpty(mainConfig.getMainClass())) {
throw new MojoFailureException("configuration.mainConfig.mainClass config cannot be empty");
}
String fileName = mainConfig.getFileName();
if(ObjectUtils.isEmpty(fileName)) {
MavenProject project = repackageMojo.getProject();
mainConfig.setFileName(project.getArtifactId() + "-" + project.getVersion() + "-repackage");
}
String packageType = mainConfig.getPackageType();
if(ObjectUtils.isEmpty(packageType)) {
mainConfig.setPackageType(PackageType.MAIN_PACKAGE_TYPE_JAR);
}
String outputDirectory = mainConfig.getOutputDirectory();
if(ObjectUtils.isEmpty(outputDirectory)){
mainConfig.setOutputDirectory(repackageMojo.getOutputDirectory().getPath());
}
}
private void setDevelopmentMode() throws MojoFailureException{
String developmentMode = mainConfig.getDevelopmentMode();
if(!ObjectUtils.isEmpty(developmentMode)){
return;
}
try {
File file = new File(repackageMojo.getProject().getBuild().getOutputDirectory());
Set<Artifact> artifacts = repackageMojo.getProject().getArtifacts();
URL[] urls = new URL[artifacts.size() + 1];
int i = 0;
for (Artifact artifact : artifacts) {
urls[i] = artifact.getFile().toURI().toURL();
i++;
}
urls[i] = file.toURI().toURL();
URLClassLoader urlClassLoader = new URLClassLoader(urls, null);
String mainClass = repackageMojo.getMainConfig().getMainClass();
if(ObjectUtils.isEmpty(mainClass)){
throw new Exception("mainConfig.mainClass config can't be empty");
}
Class<?> aClass = urlClassLoader.loadClass(mainClass);
Method method = ReflectionUtils.findMethod(aClass, Constant.DEVELOPMENT_MODE_METHOD_NAME);
String methodKey = aClass.getName() + "#" + Constant.DEVELOPMENT_MODE_METHOD_NAME + "()";
if(method == null){
throw new Exception("Not found method : " + methodKey);
}
method.setAccessible(true);
Object o = aClass.getConstructor().newInstance();
Object result = method.invoke(o);
if(ObjectUtils.isEmpty(result)){
throw new Exception(methodKey + " return value can't be empty");
}
getMainConfig().setDevelopmentMode(String.valueOf(result));
} catch (Exception e) {
throw new MojoFailureException("Set developmentMode failure:" + e.getMessage());
}
}
}

View File

@ -1,156 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack.prod;
import com.gitee.starblues.common.*;
import com.gitee.starblues.plugin.pack.RepackageMojo;
import com.gitee.starblues.plugin.pack.dev.DevRepackager;
import com.gitee.starblues.plugin.pack.utils.CommonUtils;
import com.gitee.starblues.utils.FilesUtils;
import com.gitee.starblues.utils.ObjectUtils;
import org.apache.commons.io.FileUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Properties;
import java.util.Set;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import static com.gitee.starblues.common.PackageStructure.*;
/**
*
*
* @author starBlues
* @since 3.0.0
* @version 3.1.1
*/
public class DirProdRepackager extends DevRepackager {
protected final ProdConfig prodConfig;
public DirProdRepackager(RepackageMojo repackageMojo, ProdConfig prodConfig) {
super(repackageMojo);
this.prodConfig = prodConfig;
}
@Override
public void repackage() throws MojoExecutionException, MojoFailureException {
super.repackage();
try {
resolveClasses();
logSuccess();
} catch (Exception e) {
repackageMojo.getLog().error(e.getMessage(), e);
throw new MojoFailureException(e);
}
}
protected void logSuccess(){
repackageMojo.getLog().info("Success package prod dir file : " + getRootDir());
}
@Override
protected String createRootDir() throws MojoFailureException {
String fileName = prodConfig.getFileName();
String dirPath = FilesUtils.joiningFilePath(prodConfig.getOutputDirectory(), fileName);
File dirFile = new File(dirPath);
CommonUtils.deleteFile(dirFile);
if(!dirFile.mkdirs()){
throw new MojoFailureException("Create package dir failure: " + dirFile.getPath());
}
return dirFile.getPath();
}
@Override
protected String getRelativeManifestPath() {
return FilesUtils.joiningFilePath(META_INF_NAME, MANIFEST);
}
@Override
protected String getRelativePluginMetaPath() {
return FilesUtils.joiningFilePath(META_INF_NAME, PLUGIN_META_NAME);
}
@Override
protected String getRelativeResourcesDefinePath() {
return FilesUtils.joiningFilePath(META_INF_NAME, RESOURCES_DEFINE_NAME);
}
@Override
protected Manifest getManifest() throws Exception {
Manifest manifest = super.getManifest();
Attributes attributes = manifest.getMainAttributes();
attributes.putValue(ManifestKey.PLUGIN_META_PATH, PROD_PLUGIN_META_PATH);
attributes.putValue(ManifestKey.PLUGIN_PACKAGE_TYPE, PackageType.PLUGIN_PACKAGE_TYPE_DIR);
return manifest;
}
@Override
protected Properties createPluginMetaInfo() throws Exception {
Properties properties = super.createPluginMetaInfo();
properties.put(PluginDescriptorKey.PLUGIN_PATH, CLASSES_NAME);
properties.put(PluginDescriptorKey.PLUGIN_RESOURCES_CONFIG, PROD_RESOURCES_DEFINE_PATH);
String libDir = prodConfig.getLibDir();
if(ObjectUtils.isEmpty(libDir)){
libDir = Constants.RELATIVE_SIGN + PackageStructure.PROD_LIB_PATH;
}
properties.put(PluginDescriptorKey.PLUGIN_LIB_DIR, libDir);
return properties;
}
protected void resolveClasses() throws Exception {
String buildDir = repackageMojo.getProject().getBuild().getOutputDirectory();
String path = FilesUtils.joiningFilePath(getRootDir(), CLASSES_NAME);
File file = new File(path);
FileUtils.forceMkdir(file);
FileUtils.copyDirectory(new File(buildDir), file);
}
@Override
protected Set<String> getDependenciesIndexSet() throws Exception {
Set<Artifact> dependencies = repackageMojo.getFilterDependencies();
String libDir = createLibDir();
Set<String> dependencyIndexNames = new LinkedHashSet<>(dependencies.size());
for (Artifact artifact : dependencies) {
if(filterArtifact(artifact)){
continue;
}
File artifactFile = artifact.getFile();
FileUtils.copyFile(artifactFile, new File(FilesUtils.joiningFilePath(libDir, artifactFile.getName())));
dependencyIndexNames.add(artifactFile.getName() + repackageMojo.resolveLoadToMain(artifact));
}
return dependencyIndexNames;
}
protected String createLibDir() throws IOException {
String dir = FilesUtils.joiningFilePath(getRootDir(), PackageStructure.LIB_NAME);
File file = new File(dir);
if(file.mkdir()){
return dir;
}
throw new IOException("Create " + PackageStructure.LIB_NAME + " dir failure");
}
}

View File

@ -1,77 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack.prod;
import com.gitee.starblues.common.ManifestKey;
import com.gitee.starblues.common.PackageType;
import com.gitee.starblues.common.PluginDescriptorKey;
import com.gitee.starblues.plugin.pack.RepackageMojo;
import com.gitee.starblues.plugin.pack.utils.PackageJar;
import com.gitee.starblues.plugin.pack.utils.PackageZip;
import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.apache.commons.compress.archivers.jar.JarArchiveEntry;
import org.apache.commons.compress.archivers.jar.JarArchiveOutputStream;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import java.io.*;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import static com.gitee.starblues.common.PackageStructure.PROD_CLASSES_PATH;
import static com.gitee.starblues.common.PackageStructure.PROD_RESOURCES_DEFINE_PATH;
/**
* jar
*
* @author starBlues
* @since 3.0.0
* @version 3.1.1
*/
public class JarNestedProdRepackager extends ZipProdRepackager {
public JarNestedProdRepackager(RepackageMojo repackageMojo, ProdConfig prodConfig) {
super(repackageMojo, prodConfig);
}
@Override
public void repackage() throws MojoExecutionException, MojoFailureException {
super.repackage();
}
protected void logSuccess(){
repackageMojo.getLog().info("Success package prod jar file : "
+ packageZip.getFile().getPath());
}
@Override
protected PackageZip getPackageZip() throws Exception {
return new PackageJar(prodConfig.getOutputDirectory(), prodConfig.getFileName());
}
@Override
protected Manifest getManifest() throws Exception {
Manifest manifest = super.getManifest();
manifest.getMainAttributes().putValue(
ManifestKey.PLUGIN_PACKAGE_TYPE, PackageType.PLUGIN_PACKAGE_TYPE_JAR);
return manifest;
}
}

View File

@ -1,56 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack.prod;
import com.gitee.starblues.common.ManifestKey;
import com.gitee.starblues.common.PackageType;
import com.gitee.starblues.common.PluginDescriptorKey;
import com.gitee.starblues.plugin.pack.RepackageMojo;
import com.gitee.starblues.plugin.pack.utils.PackageJar;
import com.gitee.starblues.plugin.pack.utils.PackageZip;
import java.util.jar.Manifest;
/**
* jar-outer
*
* @author starBlues
* @since 3.0.0
* @version 3.0.0
*/
public class JarOuterProdRepackager extends ZipOuterProdRepackager {
public JarOuterProdRepackager(RepackageMojo repackageMojo, ProdConfig prodConfig) {
super(repackageMojo, prodConfig);
}
@Override
protected PackageZip getPackageZip(String rootDir) throws Exception {
return new PackageJar(rootDir, super.prodConfig.getFileName());
}
@Override
protected Manifest getManifest() throws Exception {
Manifest manifest = super.getManifest();
manifest.getMainAttributes().putValue(ManifestKey.PLUGIN_PACKAGE_TYPE,
PackageType.PLUGIN_PACKAGE_TYPE_JAR_OUTER);
return manifest;
}
}

View File

@ -1,59 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack.prod;
import lombok.Data;
import org.apache.maven.plugins.annotations.Parameter;
/**
*
*
* @author starBlues
* @since 3.0.0
* @version 3.0.2
*/
@Data
public class ProdConfig {
/**
* jar
* {@link com.gitee.starblues.common.PackageType#PLUGIN_PACKAGE_TYPE_JAR}
* {@link com.gitee.starblues.common.PackageType#PLUGIN_PACKAGE_TYPE_JAR_OUTER}
* {@link com.gitee.starblues.common.PackageType#PLUGIN_PACKAGE_TYPE_ZIP}
* {@link com.gitee.starblues.common.PackageType#PLUGIN_PACKAGE_TYPE_ZIP_OUTER}
* {@link com.gitee.starblues.common.PackageType#PLUGIN_PACKAGE_TYPE_DIR}
*/
@Parameter(required = true, defaultValue = "jar")
private String packageType = "jar";
/**
* pluginId-version-repackage
*/
private String fileName;
/**
* target
*/
private String outputDirectory;
/**
* jar-outerzip-outerdir
*/
private String libDir;
}

View File

@ -1,95 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack.prod;
import com.gitee.starblues.common.PackageType;
import com.gitee.starblues.plugin.pack.PluginInfo;
import com.gitee.starblues.plugin.pack.RepackageMojo;
import com.gitee.starblues.plugin.pack.Repackager;
import com.gitee.starblues.plugin.pack.dev.DevRepackager;
import com.gitee.starblues.utils.ObjectUtils;
import lombok.Getter;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
/**
*
*
* @author starBlues
* @since 3.0.0
* @version 3.0.0
*/
public class ProdRepackager implements Repackager {
@Getter
private ProdConfig prodConfig;
private final RepackageMojo repackageMojo;
private final Repackager repackager;
public ProdRepackager(RepackageMojo repackageMojo) {
this.repackageMojo = repackageMojo;
this.repackager = new DevRepackager(repackageMojo);
}
@Override
public void repackage() throws MojoExecutionException, MojoFailureException {
repackager.repackage();
this.prodConfig = getProdConfig(repackageMojo);
String packageType = prodConfig.getPackageType();
Repackager repackager = null;
if(PackageType.PLUGIN_PACKAGE_TYPE_ZIP.equalsIgnoreCase(packageType)){
repackager = new ZipProdRepackager(repackageMojo, prodConfig);
} else if(PackageType.PLUGIN_PACKAGE_TYPE_JAR.equalsIgnoreCase(packageType)){
repackager = new JarNestedProdRepackager(repackageMojo, prodConfig);
} else if(PackageType.PLUGIN_PACKAGE_TYPE_ZIP_OUTER.equalsIgnoreCase(packageType)){
repackager = new ZipOuterProdRepackager(repackageMojo, prodConfig);
} else if(PackageType.PLUGIN_PACKAGE_TYPE_JAR_OUTER.equalsIgnoreCase(packageType)){
repackager = new JarOuterProdRepackager(repackageMojo, prodConfig);
} else if(PackageType.PLUGIN_PACKAGE_TYPE_DIR.equalsIgnoreCase(packageType)){
repackager = new DirProdRepackager(repackageMojo, prodConfig);
} else {
throw new MojoFailureException("Not found packageType : " + packageType);
}
repackager.repackage();
}
protected ProdConfig getProdConfig(RepackageMojo repackageMojo){
ProdConfig prodConfig = repackageMojo.getProdConfig();
if(prodConfig == null){
prodConfig = new ProdConfig();
}
if(ObjectUtils.isEmpty(prodConfig.getPackageType())){
prodConfig.setPackageType(PackageType.PLUGIN_PACKAGE_TYPE_JAR);
}
String fileName = prodConfig.getFileName();
if(ObjectUtils.isEmpty(fileName)) {
PluginInfo pluginInfo = repackageMojo.getPluginInfo();
prodConfig.setFileName(pluginInfo.getId() + "-" + pluginInfo.getVersion() + "-repackage");
}
String outputDirectory = prodConfig.getOutputDirectory();
if(ObjectUtils.isEmpty(outputDirectory)){
prodConfig.setOutputDirectory(repackageMojo.getOutputDirectory().getPath());
}
return prodConfig;
}
}

View File

@ -1,128 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack.prod;
import com.gitee.starblues.common.ManifestKey;
import com.gitee.starblues.common.PackageType;
import com.gitee.starblues.common.PluginDescriptorKey;
import com.gitee.starblues.plugin.pack.Constant;
import com.gitee.starblues.plugin.pack.RepackageMojo;
import com.gitee.starblues.plugin.pack.utils.PackageJar;
import com.gitee.starblues.plugin.pack.utils.PackageZip;
import com.gitee.starblues.utils.FilesUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import java.io.File;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import static com.gitee.starblues.common.PackageStructure.*;
/**
* zip-outer
*
* @author starBlues
* @since 3.0.0
* @version 3.0.0
*/
public class ZipOuterProdRepackager extends DirProdRepackager {
protected PackageZip packageZip;
public ZipOuterProdRepackager(RepackageMojo repackageMojo, ProdConfig prodConfig) {
super(repackageMojo, prodConfig);
}
@Override
public void repackage() throws MojoExecutionException, MojoFailureException {
try {
super.repackage();
} catch (Exception e){
throw new MojoFailureException(e);
} finally {
if(packageZip != null){
IOUtils.closeQuietly(packageZip);
}
}
}
@Override
protected String createRootDir() throws MojoFailureException {
String rootDir = super.createRootDir();
try {
packageZip = getPackageZip(rootDir);
return rootDir;
} catch (Exception e) {
throw new MojoFailureException(e);
}
}
protected PackageZip getPackageZip(String rootDir) throws Exception {
return new PackageZip(rootDir, super.prodConfig.getFileName());
}
@Override
protected void resolveClasses() throws Exception {
String buildDir = repackageMojo.getProject().getBuild().getOutputDirectory();
packageZip.copyDirToPackage(new File(buildDir), "");
}
@Override
protected Manifest getManifest() throws Exception {
Manifest manifest = super.getManifest();
Attributes attributes = manifest.getMainAttributes();
attributes.putValue(ManifestKey.PLUGIN_META_PATH, PROD_PLUGIN_META_PATH);
attributes.putValue(ManifestKey.PLUGIN_PACKAGE_TYPE, PackageType.PLUGIN_PACKAGE_TYPE_ZIP_OUTER);
return manifest;
}
@Override
protected Properties createPluginMetaInfo() throws Exception {
Properties properties = super.createPluginMetaInfo();
properties.put(PluginDescriptorKey.PLUGIN_PATH, packageZip.getFileName());
return properties;
}
@Override
protected void writeManifest(Manifest manifest) throws Exception {
packageZip.writeManifest(manifest);
}
@Override
protected String writePluginMetaInfo(Properties properties) throws Exception {
packageZip.write(PROD_PLUGIN_META_PATH, outputStream->{
properties.store(new OutputStreamWriter(outputStream, StandardCharsets.UTF_8),
Constant.PLUGIN_METE_COMMENTS);
});
return PROD_PLUGIN_META_PATH;
}
@Override
protected String writeResourcesDefineFile(String resourcesDefineContent) throws Exception {
packageZip.write(PROD_RESOURCES_DEFINE_PATH, resourcesDefineContent);
return PROD_RESOURCES_DEFINE_PATH;
}
}

View File

@ -1,197 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack.prod;
import com.gitee.starblues.common.ManifestKey;
import com.gitee.starblues.common.PackageStructure;
import com.gitee.starblues.common.PackageType;
import com.gitee.starblues.common.PluginDescriptorKey;
import com.gitee.starblues.plugin.pack.Constant;
import com.gitee.starblues.plugin.pack.RepackageMojo;
import com.gitee.starblues.plugin.pack.dev.Dependency;
import com.gitee.starblues.plugin.pack.dev.DevConfig;
import com.gitee.starblues.plugin.pack.dev.DevRepackager;
import com.gitee.starblues.plugin.pack.utils.CommonUtils;
import com.gitee.starblues.plugin.pack.utils.PackageZip;
import com.gitee.starblues.utils.FilesUtils;
import com.gitee.starblues.utils.ObjectUtils;
import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import static com.gitee.starblues.common.PackageStructure.*;
/**
* zip
*
* @author starBlues
* @since 3.0.0
* @version 3.0.0
*/
public class ZipProdRepackager extends DevRepackager {
protected final ProdConfig prodConfig;
protected PackageZip packageZip;
public ZipProdRepackager(RepackageMojo repackageMojo, ProdConfig prodConfig) {
super(repackageMojo);
this.prodConfig = prodConfig;
}
@Override
public void repackage() throws MojoExecutionException, MojoFailureException {
try {
packageZip = getPackageZip();
super.repackage();
resolveClasses();
resolveResourcesDefine();
String rootDir = getRootDir();
try {
FileUtils.deleteDirectory(new File(rootDir));
} catch (IOException e) {
// 忽略
}
logSuccess();
} catch (Exception e){
repackageMojo.getLog().error(e.getMessage(), e);
throw new MojoFailureException(e);
} finally {
if(packageZip != null){
IOUtils.closeQuietly(packageZip);
}
}
}
protected void logSuccess(){
repackageMojo.getLog().info("Success package prod zip file : "
+ packageZip.getFile().getPath());
}
protected PackageZip getPackageZip() throws Exception {
return new PackageZip(prodConfig.getOutputDirectory(), prodConfig.getFileName());
}
@Override
protected String getBasicRootDir(){
File outputDirectory = repackageMojo.getOutputDirectory();
return FilesUtils.joiningFilePath(outputDirectory.getPath(), UUID.randomUUID().toString());
}
@Override
protected Map<String, Dependency> getModuleDependencies(DevConfig devConfig) {
// 将项目中模块依赖置为空
return Collections.emptyMap();
}
@Override
protected String getPluginPath() {
return CLASSES_NAME + SEPARATOR;
}
@Override
protected boolean filterArtifact(Artifact artifact) {
return Constant.scopeFilter(artifact.getScope());
}
protected void resolveClasses() throws Exception {
String buildDir = repackageMojo.getProject().getBuild().getOutputDirectory();
packageZip.copyDirToPackage(new File(buildDir), null);
}
@Override
protected Manifest getManifest() throws Exception {
Manifest manifest = super.getManifest();
Attributes attributes = manifest.getMainAttributes();
attributes.putValue(ManifestKey.PLUGIN_META_PATH, PROD_PLUGIN_META_PATH);
attributes.putValue(ManifestKey.PLUGIN_PACKAGE_TYPE, PackageType.PLUGIN_PACKAGE_TYPE_ZIP);
return manifest;
}
@Override
protected Properties createPluginMetaInfo() throws Exception {
Properties properties = super.createPluginMetaInfo();
properties.put(PluginDescriptorKey.PLUGIN_RESOURCES_CONFIG, PROD_RESOURCES_DEFINE_PATH);
properties.put(PluginDescriptorKey.PLUGIN_LIB_DIR, PROD_LIB_PATH);
return properties;
}
@Override
protected void writeManifest(Manifest manifest) throws Exception {
packageZip.writeManifest(manifest);
}
@Override
protected String writePluginMetaInfo(Properties properties) throws Exception {
packageZip.write(PROD_PLUGIN_META_PATH, outputStream->{
properties.store(new OutputStreamWriter(outputStream, StandardCharsets.UTF_8),
Constant.PLUGIN_METE_COMMENTS);
});
return PROD_PLUGIN_META_PATH;
}
protected void resolveResourcesDefine() throws Exception{
Set<String> dependencyIndexNames = resolveDependencies();
StringBuilder content = new StringBuilder();
content.append(RESOURCES_DEFINE_DEPENDENCIES).append("\n");
for (String dependencyIndexName : dependencyIndexNames) {
content.append(dependencyIndexName).append("\n");
}
String loadMainResources = super.getLoadMainResources();
if(!ObjectUtils.isEmpty(loadMainResources)){
content.append(loadMainResources).append("\n");
}
final byte[] bytes = content.toString().getBytes(StandardCharsets.UTF_8);
try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes)){
packageZip.putInputStreamEntry(PROD_RESOURCES_DEFINE_PATH, byteArrayInputStream);
}
}
protected Set<String> resolveDependencies() throws Exception {
Set<Artifact> dependencies = repackageMojo.getFilterDependencies();
String libDirEntryName = createLibEntry();
Set<String> dependencyIndexNames = new LinkedHashSet<>(dependencies.size());
for (Artifact artifact : dependencies) {
if(filterArtifact(artifact)){
continue;
}
File artifactFile = artifact.getFile();
packageZip.writeDependency(artifactFile, libDirEntryName);
// fix 解决依赖前缀携带, lib 配置的前缀
dependencyIndexNames.add(artifactFile.getName());
}
return dependencyIndexNames;
}
protected String createLibEntry() throws Exception {
String libDirEntryName = PROD_LIB_PATH;
packageZip.putDirEntry(libDirEntryName);
return libDirEntryName;
}
}

View File

@ -1,100 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack.utils;
import com.gitee.starblues.plugin.pack.filter.Exclude;
import org.apache.commons.io.FileUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Objects;
import java.util.jar.JarFile;
/**
* Object
*
* @author starBlues
* @since 3.0.0
* @version 3.0.1
*/
public class CommonUtils {
public final static String PLUGIN_FRAMEWORK_GROUP_ID = "com.gitee.starblues";
public final static String PLUGIN_FRAMEWORK_ARTIFACT_ID = "spring-brick";
public final static String PLUGIN_FRAMEWORK_LOADER_ARTIFACT_ID = "spring-brick-loader";
public static final String PATTERN = "yyyy-MM-dd HH:mm:ss";
public static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern(PATTERN);
private CommonUtils(){}
public static Exclude getPluginFrameworkExclude(){
return Exclude.get(PLUGIN_FRAMEWORK_GROUP_ID, PLUGIN_FRAMEWORK_ARTIFACT_ID);
}
public static boolean isPluginFramework(Artifact artifact){
return Objects.equals(artifact.getGroupId(), PLUGIN_FRAMEWORK_GROUP_ID)
&& Objects.equals(artifact.getArtifactId(), PLUGIN_FRAMEWORK_ARTIFACT_ID);
}
public static boolean isPluginFrameworkLoader(Artifact artifact){
return Objects.equals(artifact.getGroupId(), PLUGIN_FRAMEWORK_GROUP_ID)
&& Objects.equals(artifact.getArtifactId(), PLUGIN_FRAMEWORK_LOADER_ARTIFACT_ID);
}
public static JarFile getSourceJarFile(MavenProject mavenProject) {
File file = mavenProject.getArtifact().getFile();
try {
return new JarFile(file);
} catch (Exception e){
return null;
}
}
public static String getDateTime() {
return DATE_TIME_FORMATTER.format(LocalDateTime.now());
}
public static void deleteFile(File rootFile) throws MojoFailureException {
try {
if(rootFile == null){
return;
}
if(!rootFile.exists()){
return;
}
if(rootFile.isFile()){
FileUtils.delete(rootFile);
} else {
FileUtils.deleteDirectory(rootFile);
}
} catch (Exception e){
e.printStackTrace();
throw new MojoFailureException("Delete file '" + rootFile.getPath() + "' failure. " + e.getMessage());
}
}
}

View File

@ -1,58 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack.utils;
import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.apache.commons.compress.archivers.jar.JarArchiveEntry;
import org.apache.commons.compress.archivers.jar.JarArchiveOutputStream;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import java.io.File;
import java.io.FileOutputStream;
import java.nio.file.Files;
/**
* jar
*
* @author starBlues
* @since 3.0.0
* @version 3.0.0
*/
public class PackageJar extends PackageZip{
public PackageJar(File file) throws Exception {
super(file);
}
public PackageJar(String outputDirectory, String packageName) throws Exception {
super(outputDirectory, packageName);
}
@Override
protected String getPackageFileSuffix() {
return "jar";
}
@Override
protected ArchiveOutputStream getOutputStream(File packFile) throws Exception {
return new JarArchiveOutputStream(Files.newOutputStream(packFile.toPath()));
}
@Override
protected ZipArchiveEntry getArchiveEntry(String name) {
return new JarArchiveEntry(name);
}
}

View File

@ -1,249 +0,0 @@
/**
* Copyright [2019-Present] [starBlues]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.starblues.plugin.pack.utils;
import com.gitee.starblues.common.PackageStructure;
import com.gitee.starblues.utils.FilesUtils;
import com.gitee.starblues.utils.ObjectUtils;
import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.apache.commons.compress.archivers.zip.UnixStat;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.apache.commons.compress.archivers.zip.ZipFile;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import java.io.*;
import java.nio.file.Files;
import java.util.Enumeration;
import java.util.jar.Manifest;
import java.util.zip.CRC32;
import java.util.zip.ZipEntry;
import static com.gitee.starblues.common.PackageStructure.*;
/**
* zip
*
* @author starBlues
* @since 3.0.0
* @version 3.0.0
*/
public class PackageZip implements Closeable{
private static final int UNIX_FILE_MODE = UnixStat.FILE_FLAG | UnixStat.DEFAULT_FILE_PERM;
private static final int UNIX_DIR_MODE = UnixStat.DIR_FLAG | UnixStat.DEFAULT_DIR_PERM;
private final File file;
private final ArchiveOutputStream outputStream;
public PackageZip(File file) throws Exception {
this.file = file;
this.outputStream = getOutputStream(file);
}
public PackageZip(String outputDirectory, String packageName) throws Exception{
String rootPath = FilesUtils.joiningFilePath(outputDirectory, packageName);
this.file = getPackageFile(rootPath);
this.outputStream = getOutputStream(file);
}
public File getFile(){
return file;
}
public String getFileName(){
return file.getName();
}
protected File getPackageFile(String rootPath) throws Exception {
String fileSuffix = getPackageFileSuffix();
File file = new File(rootPath + "." + fileSuffix);
CommonUtils.deleteFile(file);
if(file.createNewFile()){
return file;
}
throw new IOException("Create file '" + file.getPath() + "' failure.");
}
protected String getPackageFileSuffix(){
return "zip";
}
protected ArchiveOutputStream getOutputStream(File packFile) throws Exception {
return new ZipArchiveOutputStream(Files.newOutputStream(packFile.toPath()));
}
public void copyDirToPackage(File rootDir, String packageDir) throws Exception {
if(packageDir == null){
packageDir = rootDir.getName();
}
if (rootDir.isDirectory()) {
File[] childFiles = rootDir.listFiles();
if(ObjectUtils.isEmpty(packageDir)){
packageDir = "";
} else {
packageDir = packageDir + "/";
putDirEntry(packageDir);
}
if(childFiles == null){
return;
}
for (File childFile : childFiles) {
copyDirToPackage(childFile, packageDir + childFile.getName());
}
} else {
putFileEntry(rootDir, packageDir);
}
}
public void copyZipToPackage(File sourceZipFile) throws Exception {
if(sourceZipFile == null || !sourceZipFile.exists()){
return;
}
try (ZipFile zipFile = new ZipFile(sourceZipFile)){
Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();
while (entries.hasMoreElements()){
ZipArchiveEntry zipArchiveEntry = entries.nextElement();
String name = zipArchiveEntry.getName();
if(name.contains(PackageStructure.META_INF_NAME)){
// 不拷贝 mate-inf
continue;
}
if(zipArchiveEntry.isDirectory()){
putDirEntry(name);
} else {
try (InputStream inputStream = zipFile.getInputStream(zipArchiveEntry)){
putInputStreamEntry(name, inputStream);
}
}
}
}
}
public String writeDependency(File dependencyFile, String libDirEntryName) throws Exception {
String indexName = libDirEntryName + dependencyFile.getName();
ZipArchiveEntry entry = getArchiveEntry(indexName);
entry.setTime(System.currentTimeMillis());
entry.setUnixMode(indexName.endsWith("/") ? UNIX_DIR_MODE : UNIX_FILE_MODE);
entry.getGeneralPurposeBit().useUTF8ForNames(true);
try(FileInputStream inputStream = new FileInputStream(dependencyFile)){
new CrcAndSize(inputStream).setupStoredEntry(entry);
}
try (FileInputStream inputStream = new FileInputStream(dependencyFile)){
outputStream.putArchiveEntry(entry);
IOUtils.copy(inputStream, outputStream);
outputStream.closeArchiveEntry();
}
return indexName;
}
public void putFileEntry(File destFile, String rootDir) throws Exception {
if(!destFile.exists()){
throw new FileNotFoundException("Not found file : " + destFile.getPath());
}
outputStream.putArchiveEntry(getArchiveEntry(rootDir));
FileUtils.copyFile(destFile, outputStream);
outputStream.closeArchiveEntry();
}
public void putInputStreamEntry(String name, InputStream inputStream) throws Exception {
outputStream.putArchiveEntry(getArchiveEntry(name));
IOUtils.copy(inputStream, outputStream);
outputStream.closeArchiveEntry();
}
public void write(String name, String content) throws Exception {
outputStream.putArchiveEntry(getArchiveEntry(name));
IOUtils.write(content, outputStream, CHARSET_NAME);
outputStream.closeArchiveEntry();
}
public void write(String name, Writer writer) throws Exception {
outputStream.putArchiveEntry(getArchiveEntry(name));
writer.write(outputStream);
outputStream.closeArchiveEntry();
}
public void write(String name, File file) throws Exception {
outputStream.putArchiveEntry(getArchiveEntry(name));
try (FileInputStream fileInputStream = new FileInputStream(file)){
IOUtils.copy(fileInputStream, outputStream);
outputStream.closeArchiveEntry();
}
}
public void writeManifest(Manifest manifest) throws Exception {
putDirEntry(META_INF_NAME + SEPARATOR);
write(PROD_MANIFEST_PATH, manifest::write);
}
public void putDirEntry(String dir) throws IOException {
outputStream.putArchiveEntry(getArchiveEntry(dir));
outputStream.closeArchiveEntry();
}
protected ZipArchiveEntry getArchiveEntry(String name){
return new ZipArchiveEntry(name);
}
@Override
public void close() throws IOException {
outputStream.finish();
outputStream.close();
}
private static class CrcAndSize {
private static final int BUFFER_SIZE = 32 * 1024;
private final CRC32 crc = new CRC32();
private long size;
CrcAndSize(InputStream inputStream) throws IOException {
load(inputStream);
}
private void load(InputStream inputStream) throws IOException {
byte[] buffer = new byte[BUFFER_SIZE];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
this.crc.update(buffer, 0, bytesRead);
this.size += bytesRead;
}
}
void setupStoredEntry(ZipArchiveEntry entry) {
entry.setSize(this.size);
entry.setCompressedSize(this.size);
entry.setCrc(this.crc.getValue());
entry.setMethod(ZipEntry.STORED);
}
}
@FunctionalInterface
public interface Writer{
void write(ArchiveOutputStream outputStream) throws Exception;
}
}

View File

@ -1,168 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin>
<name>Spring Boot Plugin Maven Packager</name>
<groupId>com.gitee.starblues</groupId>
<artifactId>spring-brick-maven-packager</artifactId>
<version>3.1.3</version>
<goalPrefix>spring-brick-packager</goalPrefix>
<isolatedRealm>false</isolatedRealm>
<inheritedByDefault>true</inheritedByDefault>
<mojos>
<mojo>
<goal>repackage</goal>
<description>重新打包</description>
<requiresDependencyResolution>compile+runtime</requiresDependencyResolution>
<requiresDirectInvocation>false</requiresDirectInvocation>
<requiresProject>true</requiresProject>
<requiresReports>false</requiresReports>
<aggregator>false</aggregator>
<requiresOnline>false</requiresOnline>
<inheritedByDefault>true</inheritedByDefault>
<phase>package</phase>
<implementation>com.gitee.starblues.plugin.pack.RepackageMojo</implementation>
<language>java</language>
<instantiationStrategy>per-lookup</instantiationStrategy>
<executionStrategy>once-per-session</executionStrategy>
<since>3.0.0</since>
<requiresDependencyCollection>compile+runtime</requiresDependencyCollection>
<threadSafe>true</threadSafe>
<parameters>
<parameter>
<name>project</name>
<type>org.apache.maven.project.MavenProject</type>
<since>3.0.0</since>
<required>true</required>
<editable>false</editable>
<description>当前项目</description>
</parameter>
<parameter>
<name>outputDirectory</name>
<type>java.io.File</type>
<since>3.0.0</since>
<required>true</required>
<editable>true</editable>
<description>打包输出目录地址</description>
</parameter>
<parameter>
<name>includes</name>
<type>java.util.List</type>
<since>3.0.0</since>
<required>false</required>
<editable>true</editable>
<description>包含依赖定义</description>
</parameter>
<parameter>
<name>excludes</name>
<type>java.util.List</type>
<since>3.0.0</since>
<required>false</required>
<editable>true</editable>
<description>排除依赖定义</description>
</parameter>
<parameter>
<name>skip</name>
<type>boolean</type>
<since>3.0.0</since>
<required>false</required>
<editable>true</editable>
<description>跳过执行</description>
</parameter>
<parameter>
<name>mode</name>
<type>string</type>
<since>3.0.0</since>
<required>true</required>
<editable>true</editable>
<description>打包模式: dev/prod ,默认为dev</description>
</parameter>
<parameter>
<name>pluginInfo</name>
<type>com.gitee.starblues.plugin.pack.PluginInfo</type>
<since>3.0.0</since>
<required>false</required>
<editable>true</editable>
<description>插件信息</description>
</parameter>
<parameter>
<name>loadMainResourcePattern</name>
<type>com.gitee.starblues.plugin.pack.LoadMainResourcePattern</type>
<since>3.0.0</since>
<required>false</required>
<editable>true</editable>
<description>从主程序加载资源的定义</description>
</parameter>
<parameter>
<name>devConfig</name>
<type>com.gitee.starblues.plugin.pack.dev.DevConfig</type>
<since>3.0.0</since>
<required>false</required>
<editable>true</editable>
<description>dev打包模式配置</description>
</parameter>
<parameter>
<name>prodConfig</name>
<type>com.gitee.starblues.plugin.pack.prod.ProdConfig</type>
<since>3.0.0</since>
<required>false</required>
<editable>true</editable>
<description>prod打包模式配置</description>
</parameter>
<parameter>
<name>mainConfig</name>
<type>com.gitee.starblues.plugin.pack.main.MainConfig</type>
<since>3.0.0</since>
<required>false</required>
<editable>true</editable>
<description>main打包模式配置</description>
</parameter>
<parameter>
<name>loadToMain</name>
<type>com.gitee.starblues.plugin.pack.LoadToMain</type>
<since>3.0.0</since>
<required>false</required>
<editable>true</editable>
<description>加载到主程序的依赖</description>
</parameter>
<parameter>
<name>encryptConfig</name>
<type>com.gitee.starblues.plugin.pack.encrypt.EncryptConfig</type>
<since>3.0.1</since>
<required>false</required>
<editable>true</editable>
<description>加密配置</description>
</parameter>
<parameter>
<name>includeSystemScope</name>
<type>boolean</type>
<since>3.0.2</since>
<required>false</required>
<editable>true</editable>
<description>是否包含scope类型为system的依赖</description>
</parameter>
</parameters>
<configuration>
<project implementation="org.apache.maven.project.MavenProject" default-value="${project}"/>
<outputDirectory implementation="java.io.File" default-value="${project.build.directory}"/>
<skip implementation="boolean" default-value="false"/>
<mode implementation="string" default-value="dev"/>
<pluginInfo implementation="com.gitee.starblues.plugin.pack.PluginInfo" />
<loadMainResourcePattern implementation="com.gitee.starblues.plugin.pack.LoadMainResourcePattern" />
<includes implementation="java.util.List">${springboot-plugin.includes}</includes>
<excludes implementation="java.util.List">${springboot-plugin.excludes}</excludes>
<devConfig implementation="com.gitee.starblues.plugin.pack.dev.DevConfig" />
<prodConfig implementation="com.gitee.starblues.plugin.pack.prod.ProdConfig" />
<mainConfig implementation="com.gitee.starblues.plugin.pack.main.MainConfig" />
<loadToMain implementation="com.gitee.starblues.plugin.pack.LoadToMain" />
<includeSystemScope implementation="boolean" default-value="true" />
</configuration>
<requirements>
<requirement>
<role>org.apache.maven.project.MavenProjectHelper</role>
<field-name>projectHelper</field-name>
</requirement>
</requirements>
</mojo>
</mojos>
<dependencies/>
</plugin>

View File

@ -1,168 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin>
<name>Spring Boot Plugin Maven Packager</name>
<groupId>com.gitee.starblues</groupId>
<artifactId>spring-brick-maven-packager</artifactId>
<version>3.1.3</version>
<goalPrefix>spring-brick-packager</goalPrefix>
<isolatedRealm>false</isolatedRealm>
<inheritedByDefault>true</inheritedByDefault>
<mojos>
<mojo>
<goal>repackage</goal>
<description>重新打包</description>
<requiresDependencyResolution>compile+runtime</requiresDependencyResolution>
<requiresDirectInvocation>false</requiresDirectInvocation>
<requiresProject>true</requiresProject>
<requiresReports>false</requiresReports>
<aggregator>false</aggregator>
<requiresOnline>false</requiresOnline>
<inheritedByDefault>true</inheritedByDefault>
<phase>package</phase>
<implementation>com.gitee.starblues.plugin.pack.RepackageMojo</implementation>
<language>java</language>
<instantiationStrategy>per-lookup</instantiationStrategy>
<executionStrategy>once-per-session</executionStrategy>
<since>3.0.0</since>
<requiresDependencyCollection>compile+runtime</requiresDependencyCollection>
<threadSafe>true</threadSafe>
<parameters>
<parameter>
<name>project</name>
<type>org.apache.maven.project.MavenProject</type>
<since>3.0.0</since>
<required>true</required>
<editable>false</editable>
<description>当前项目</description>
</parameter>
<parameter>
<name>outputDirectory</name>
<type>java.io.File</type>
<since>3.0.0</since>
<required>true</required>
<editable>true</editable>
<description>打包输出目录地址</description>
</parameter>
<parameter>
<name>includes</name>
<type>java.util.List</type>
<since>3.0.0</since>
<required>false</required>
<editable>true</editable>
<description>包含依赖定义</description>
</parameter>
<parameter>
<name>excludes</name>
<type>java.util.List</type>
<since>3.0.0</since>
<required>false</required>
<editable>true</editable>
<description>排除依赖定义</description>
</parameter>
<parameter>
<name>skip</name>
<type>boolean</type>
<since>3.0.0</since>
<required>false</required>
<editable>true</editable>
<description>跳过执行</description>
</parameter>
<parameter>
<name>mode</name>
<type>string</type>
<since>3.0.0</since>
<required>true</required>
<editable>true</editable>
<description>打包模式: dev/prod ,默认为dev</description>
</parameter>
<parameter>
<name>pluginInfo</name>
<type>com.gitee.starblues.plugin.pack.PluginInfo</type>
<since>3.0.0</since>
<required>false</required>
<editable>true</editable>
<description>插件信息</description>
</parameter>
<parameter>
<name>loadMainResourcePattern</name>
<type>com.gitee.starblues.plugin.pack.LoadMainResourcePattern</type>
<since>3.0.0</since>
<required>false</required>
<editable>true</editable>
<description>从主程序加载资源的定义</description>
</parameter>
<parameter>
<name>devConfig</name>
<type>com.gitee.starblues.plugin.pack.dev.DevConfig</type>
<since>3.0.0</since>
<required>false</required>
<editable>true</editable>
<description>dev打包模式配置</description>
</parameter>
<parameter>
<name>prodConfig</name>
<type>com.gitee.starblues.plugin.pack.prod.ProdConfig</type>
<since>3.0.0</since>
<required>false</required>
<editable>true</editable>
<description>prod打包模式配置</description>
</parameter>
<parameter>
<name>mainConfig</name>
<type>com.gitee.starblues.plugin.pack.main.MainConfig</type>
<since>3.0.0</since>
<required>false</required>
<editable>true</editable>
<description>main打包模式配置</description>
</parameter>
<parameter>
<name>loadToMain</name>
<type>com.gitee.starblues.plugin.pack.LoadToMain</type>
<since>3.0.0</since>
<required>false</required>
<editable>true</editable>
<description>加载到主程序的依赖</description>
</parameter>
<parameter>
<name>encryptConfig</name>
<type>com.gitee.starblues.plugin.pack.encrypt.EncryptConfig</type>
<since>3.0.1</since>
<required>false</required>
<editable>true</editable>
<description>加密配置</description>
</parameter>
<parameter>
<name>includeSystemScope</name>
<type>boolean</type>
<since>3.0.2</since>
<required>false</required>
<editable>true</editable>
<description>是否包含scope类型为system的依赖</description>
</parameter>
</parameters>
<configuration>
<project implementation="org.apache.maven.project.MavenProject" default-value="${project}"/>
<outputDirectory implementation="java.io.File" default-value="${project.build.directory}"/>
<skip implementation="boolean" default-value="false"/>
<mode implementation="string" default-value="dev"/>
<pluginInfo implementation="com.gitee.starblues.plugin.pack.PluginInfo" />
<loadMainResourcePattern implementation="com.gitee.starblues.plugin.pack.LoadMainResourcePattern" />
<includes implementation="java.util.List">${springboot-plugin.includes}</includes>
<excludes implementation="java.util.List">${springboot-plugin.excludes}</excludes>
<devConfig implementation="com.gitee.starblues.plugin.pack.dev.DevConfig" />
<prodConfig implementation="com.gitee.starblues.plugin.pack.prod.ProdConfig" />
<mainConfig implementation="com.gitee.starblues.plugin.pack.main.MainConfig" />
<loadToMain implementation="com.gitee.starblues.plugin.pack.LoadToMain" />
<includeSystemScope implementation="boolean" default-value="true" />
</configuration>
<requirements>
<requirement>
<role>org.apache.maven.project.MavenProjectHelper</role>
<field-name>projectHelper</field-name>
</requirement>
</requirements>
</mojo>
</mojos>
<dependencies/>
</plugin>

View File

@ -17,10 +17,6 @@ spring:
properties:
hibernate:
format_sql: true
sql:
init:
schema-locations: classpath:sql/schema.sql
mode: ALWAYS
datasource:
url: jdbc:h2:./data/iotkit;MODE=MySQL
username: sa

View File

@ -1,60 +0,0 @@
-- ----------------------------
-- 18、代码生成业务表
-- ----------------------------
create table if not exists gen_table (
table_id bigint(20) not null comment '编号',
data_name varchar(200) default '' comment '数据源名称',
table_name varchar(200) default '' comment '表名称',
table_comment varchar(500) default '' comment '表描述',
sub_table_name varchar(64) default null comment '关联子表的表名',
sub_table_fk_name varchar(64) default null comment '子表关联的外键名',
class_name varchar(100) default '' comment '实体类名称',
tpl_category varchar(200) default 'crud' comment '使用的模板crud单表操作 tree树表操作',
package_name varchar(100) comment '生成包路径',
module_name varchar(30) comment '生成模块名',
business_name varchar(30) comment '生成业务名',
function_name varchar(50) comment '生成功能名',
function_author varchar(50) comment '生成功能作者',
gen_type char(1) default '0' comment '生成代码方式0zip压缩包 1自定义路径',
gen_path varchar(200) default '/' comment '生成路径(不填默认项目路径)',
options varchar(1000) comment '其它生成选项',
create_dept bigint(20) default null comment '创建部门',
create_by bigint(20) default null comment '创建者',
create_time datetime comment '创建时间',
update_by bigint(20) default null comment '更新者',
update_time datetime comment '更新时间',
remark varchar(500) default null comment '备注',
primary key (table_id)
) engine=innodb comment = '代码生成业务表';
-- ----------------------------
-- 19、代码生成业务表字段
-- ----------------------------
create table if not exists gen_table_column (
column_id bigint(20) not null comment '编号',
table_id bigint(20) comment '归属表编号',
column_name varchar(200) comment '列名称',
column_comment varchar(500) comment '列描述',
column_type varchar(100) comment '列类型',
java_type varchar(500) comment 'JAVA类型',
java_field varchar(200) comment 'JAVA字段名',
is_pk char(1) comment '是否主键1是',
is_increment char(1) comment '是否自增1是',
is_required char(1) comment '是否必填1是',
is_insert char(1) comment '是否为插入字段1是',
is_edit char(1) comment '是否编辑字段1是',
is_list char(1) comment '是否列表字段1是',
is_query char(1) comment '是否查询字段1是',
query_type varchar(200) default 'EQ' comment '查询方式(等于、不等于、大于、小于、范围)',
html_type varchar(200) comment '显示类型(文本框、文本域、下拉框、复选框、单选框、日期控件)',
dict_type varchar(200) default '' comment '字典类型',
sort int comment '排序',
create_dept bigint(20) default null comment '创建部门',
create_by bigint(20) default null comment '创建者',
create_time datetime comment '创建时间',
update_by bigint(20) default null comment '更新者',
update_time datetime comment '更新时间',
primary key (column_id)
) engine=innodb comment = '代码生成业务表字段';

View File

@ -37,7 +37,7 @@
<lang3.version>3.7</lang3.version>
<hutool.version>5.8.18</hutool.version>
<mapstruct-plus.version>1.3.1</mapstruct-plus.version>
<spring-brick.version>3.1.2</spring-brick.version>
<spring-brick.version>3.1.3</spring-brick.version>
</properties>
<dependencyManagement>