Skip to content

Commit

Permalink
Merge pull request #1 from impactCn/main
Browse files Browse the repository at this point in the history
[type: feature] first version
  • Loading branch information
impactCn authored Sep 13, 2022
2 parents 040a870 + a974fba commit ef3938a
Show file tree
Hide file tree
Showing 7 changed files with 559 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@


*.iml
out
gen
target

.idea
91 changes: 91 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<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>

<groupId>org.apache</groupId>
<artifactId>shenyu-watcher</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.11</version>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>


</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<archive>
<manifest>
<mainClass>org.apache.shenyu.ShenyuEyes</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>./lib/</classpathPrefix>
<useUniqueVersions>false</useUniqueVersions>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>

</project>
81 changes: 81 additions & 0 deletions src/main/java/org/apache/shenyu/ShenyuWatcher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.shenyu;

import org.apache.shenyu.entity.JarDO;
import org.apache.shenyu.env.CheckEnv;
import org.apache.shenyu.util.FileUtil;
import org.apache.shenyu.util.StringUtil;

import java.util.ArrayList;
import java.util.List;

public class ShenyuWatcher {

public static void main(String[] args) {

// check py version
System.out.println("Start to check python version...");
if (CheckEnv.PYTHON_CHECK) {
System.out.println("The python version check passed.");

String filePath = args[0];

String fileName = filePath.substring(filePath.lastIndexOf("\\") + 1);

System.out.println("Start to unzip " + fileName + "...");

String destDir = filePath.substring(0, filePath.lastIndexOf("\\"));
String fileDir = fileName.replace(".tar.gz", "");

FileUtil.unTarGz(filePath, destDir);
System.out.println("Decompression succeeded.");
System.out.println("Start to check LICENSE...");
List<String> fileNames = FileUtil.getFileName(destDir + "\\" + fileDir + "\\lib");

JarDO jarDO = JarDO.build(fileNames);
String content = FileUtil.read(destDir + "\\" + fileDir + "\\LICENSE");

List<String> failureMatchJar = new ArrayList<>();

for (JarDO.ParseJar parseJar : jarDO.getParseJar()) {

if (parseJar.getOriginal().contains("shenyu")) {
continue;
}

if (!StringUtil.match(content, parseJar.getPackageName() + " " + parseJar.getVersion())) {
failureMatchJar.add(parseJar.getOriginal());
}

}

if (failureMatchJar.size() > 0) {
System.err.println("The following jars need to be modified: ");
failureMatchJar.forEach(System.err::println);
}

jarDO.setFailureMatchJar(failureMatchJar);

} else {
System.err.println("The python version not 3.8");
}

}

}
160 changes: 160 additions & 0 deletions src/main/java/org/apache/shenyu/entity/JarDO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.shenyu.entity;

import org.apache.shenyu.util.StringUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class JarDO {

private Integer total;

private Integer parseTotal;

private List<ParseJar> parseJar;

private List<String> failureParseJar;

private List<String> failureMatchJar;

public static JarDO build(final List<String> fileNames) {
JarDO jarDO = new JarDO();

int count = 0;
List<ParseJar> parseJars = new ArrayList<>();
List<String> failureParseJars = new ArrayList<>();
for (String fileName : fileNames) {
Map<String, String> parse = StringUtil.parse(fileName);

if (parse.containsKey("version")) {
count++;
ParseJar parseJar = new ParseJar();
parseJar.setOriginal(parse.get("original"));
parseJar.setPackageName(parse.get("packageName"));
parseJar.setVersion(parse.get("version"));
parseJars.add(parseJar);
} else {
failureParseJars.add(parse.get("original"));
}

}

jarDO.setTotal(fileNames.size());
jarDO.setParseTotal(count);
jarDO.setParseJar(parseJars);
jarDO.setFailureParseJar(failureParseJars);
return jarDO;
}


public static class ParseJar {

private String packageName;

private String version;

private String original;

public String getPackageName() {
return packageName;
}

public void setPackageName(String packageName) {
this.packageName = packageName;
}

public String getVersion() {
return version;
}

public void setVersion(String version) {
this.version = version;
}

public String getOriginal() {
return original;
}

public void setOriginal(String original) {
this.original = original;
}

@Override
public String toString() {
return "ParseJar{" +
"packageName='" + packageName + '\'' +
", version='" + version + '\'' +
", original='" + original + '\'' +
'}';
}
}

public Integer getTotal() {
return total;
}

public void setTotal(Integer total) {
this.total = total;
}

public Integer getParseTotal() {
return parseTotal;
}

public void setParseTotal(Integer parseTotal) {
this.parseTotal = parseTotal;
}

public List<ParseJar> getParseJar() {
return parseJar;
}

public void setParseJar(List<ParseJar> parseJar) {
this.parseJar = parseJar;
}

public List<String> getFailureParseJar() {
return failureParseJar;
}

public void setFailureParseJar(List<String> failureParseJar) {
this.failureParseJar = failureParseJar;
}

public List<String> getFailureMatchJar() {
return failureMatchJar;
}

public void setFailureMatchJar(List<String> failureMatchJar) {
this.failureMatchJar = failureMatchJar;
}

@Override
public String toString() {
return "JarDO{" +
"total=" + total +
", parseTotal=" + parseTotal +
", parseJar=" + parseJar +
", failureParseJar=" + failureParseJar +
", failureMatchJar=" + failureMatchJar +
'}';
}
}
Loading

0 comments on commit ef3938a

Please sign in to comment.