Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 make sure non java files are exploded to java project #760

Merged
merged 3 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions demo-output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,30 @@
data: dependency
innerText: "\n io.javaoperatorsdk.operator\n sample\n 0.0.0\n "
matchingXML: <groupId>io.javaoperatorsdk.operator</groupId><artifactId>sample</artifactId><version>0.0.0</version>
- uri: file:///examples/java-project/quarkus-1-6-2-jar-exploded/META-INF/maven/io.javaoperatorsdk/quarkus/pom.xml
message: <groupId>io.javaoperatorsdk</groupId><artifactId>operator-framework-quarkus-extension</artifactId><version>${project.version}</version>
codeSnip: "30 <version>${quarkus.version}</version>\n31 <type>pom</type>\n32 <scope>import</scope>\n33 </dependency>\n34 </dependencies>\n35 </dependencyManagement>\n36 \n37 <dependencies>\n38 <dependency>\n39 <groupId>io.javaoperatorsdk</groupId>\n40 <artifactId>operator-framework-quarkus-extension</artifactId>\n41 <version>${project.version}</version>\n42 </dependency>\n43 <dependency>\n44 <groupId>io.javaoperatorsdk</groupId>\n45 <artifactId>operator-framework-samples-common</artifactId>\n46 <version>${project.version}</version>\n47 </dependency>\n48 </dependencies>\n49 \n50 <build>"
lineNumber: 39
variables:
data: dependency
innerText: "\n io.javaoperatorsdk\n operator-framework-quarkus-extension\n ${project.version}\n "
matchingXML: <groupId>io.javaoperatorsdk</groupId><artifactId>operator-framework-quarkus-extension</artifactId><version>${project.version}</version>
- uri: file:///examples/java-project/quarkus-1-6-2-jar-exploded/META-INF/maven/io.javaoperatorsdk/quarkus/pom.xml
message: <groupId>io.javaoperatorsdk</groupId><artifactId>operator-framework-samples-common</artifactId><version>${project.version}</version>
codeSnip: "35 </dependencyManagement>\n36 \n37 <dependencies>\n38 <dependency>\n39 <groupId>io.javaoperatorsdk</groupId>\n40 <artifactId>operator-framework-quarkus-extension</artifactId>\n41 <version>${project.version}</version>\n42 </dependency>\n43 <dependency>\n44 <groupId>io.javaoperatorsdk</groupId>\n45 <artifactId>operator-framework-samples-common</artifactId>\n46 <version>${project.version}</version>\n47 </dependency>\n48 </dependencies>\n49 \n50 <build>\n51 <plugins>\n52 <plugin>\n53 <groupId>org.apache.maven.plugins</groupId>\n54 <artifactId>maven-compiler-plugin</artifactId>\n55 <version>${compiler-plugin.version}</version>"
lineNumber: 44
variables:
data: dependency
innerText: "\n io.javaoperatorsdk\n operator-framework-samples-common\n ${project.version}\n "
matchingXML: <groupId>io.javaoperatorsdk</groupId><artifactId>operator-framework-samples-common</artifactId><version>${project.version}</version>
- uri: file:///examples/java-project/quarkus-1-6-2-jar-exploded/META-INF/maven/io.javaoperatorsdk/quarkus/pom.xml
message: <groupId>io.quarkus</groupId><artifactId>quarkus-universe-bom</artifactId><version>${quarkus.version}</version><type>pom</type><scope>import</scope>
codeSnip: "19 <maven.compiler.target>11</maven.compiler.target>\n20 <quarkus.version>1.10.5.Final</quarkus.version>\n21 <compiler-plugin.version>3.8.1</compiler-plugin.version>\n22 <maven.compiler.parameters>true</maven.compiler.parameters>\n23 </properties>\n24 \n25 <dependencyManagement>\n26 <dependencies>\n27 <dependency>\n28 <groupId>io.quarkus</groupId>\n29 <artifactId>quarkus-universe-bom</artifactId>\n30 <version>${quarkus.version}</version>\n31 <type>pom</type>\n32 <scope>import</scope>\n33 </dependency>\n34 </dependencies>\n35 </dependencyManagement>\n36 \n37 <dependencies>\n38 <dependency>\n39 <groupId>io.javaoperatorsdk</groupId>"
lineNumber: 28
variables:
data: dependency
innerText: "\n io.quarkus\n quarkus-universe-bom\n ${quarkus.version}\n pom\n import\n "
matchingXML: <groupId>io.quarkus</groupId><artifactId>quarkus-universe-bom</artifactId><version>${quarkus.version}</version><type>pom</type><scope>import</scope>
- uri: file:///examples/java/dummy/pom.xml
message: |-
<groupId>javax</groupId><artifactId>javaee-api</artifactId><!-- This leads to https://github.com/konveyor/analyzer-lsp/issues/390
Expand Down Expand Up @@ -797,6 +821,30 @@
data: dependency
innerText: "\n io.javaoperatorsdk.operator\n sample\n 0.0.0\n "
matchingXML: <groupId>io.javaoperatorsdk.operator</groupId><artifactId>sample</artifactId><version>0.0.0</version>
- uri: file:///examples/java-project/quarkus-1-6-2-jar-exploded/META-INF/maven/io.javaoperatorsdk/quarkus/pom.xml
message: POM XML dependencies - '<groupId>io.javaoperatorsdk</groupId><artifactId>operator-framework-quarkus-extension</artifactId><version>${project.version}</version>'
codeSnip: "30 <version>${quarkus.version}</version>\n31 <type>pom</type>\n32 <scope>import</scope>\n33 </dependency>\n34 </dependencies>\n35 </dependencyManagement>\n36 \n37 <dependencies>\n38 <dependency>\n39 <groupId>io.javaoperatorsdk</groupId>\n40 <artifactId>operator-framework-quarkus-extension</artifactId>\n41 <version>${project.version}</version>\n42 </dependency>\n43 <dependency>\n44 <groupId>io.javaoperatorsdk</groupId>\n45 <artifactId>operator-framework-samples-common</artifactId>\n46 <version>${project.version}</version>\n47 </dependency>\n48 </dependencies>\n49 \n50 <build>"
lineNumber: 39
variables:
data: dependency
innerText: "\n io.javaoperatorsdk\n operator-framework-quarkus-extension\n ${project.version}\n "
matchingXML: <groupId>io.javaoperatorsdk</groupId><artifactId>operator-framework-quarkus-extension</artifactId><version>${project.version}</version>
- uri: file:///examples/java-project/quarkus-1-6-2-jar-exploded/META-INF/maven/io.javaoperatorsdk/quarkus/pom.xml
message: POM XML dependencies - '<groupId>io.javaoperatorsdk</groupId><artifactId>operator-framework-samples-common</artifactId><version>${project.version}</version>'
codeSnip: "35 </dependencyManagement>\n36 \n37 <dependencies>\n38 <dependency>\n39 <groupId>io.javaoperatorsdk</groupId>\n40 <artifactId>operator-framework-quarkus-extension</artifactId>\n41 <version>${project.version}</version>\n42 </dependency>\n43 <dependency>\n44 <groupId>io.javaoperatorsdk</groupId>\n45 <artifactId>operator-framework-samples-common</artifactId>\n46 <version>${project.version}</version>\n47 </dependency>\n48 </dependencies>\n49 \n50 <build>\n51 <plugins>\n52 <plugin>\n53 <groupId>org.apache.maven.plugins</groupId>\n54 <artifactId>maven-compiler-plugin</artifactId>\n55 <version>${compiler-plugin.version}</version>"
lineNumber: 44
variables:
data: dependency
innerText: "\n io.javaoperatorsdk\n operator-framework-samples-common\n ${project.version}\n "
matchingXML: <groupId>io.javaoperatorsdk</groupId><artifactId>operator-framework-samples-common</artifactId><version>${project.version}</version>
- uri: file:///examples/java-project/quarkus-1-6-2-jar-exploded/META-INF/maven/io.javaoperatorsdk/quarkus/pom.xml
message: POM XML dependencies - '<groupId>io.quarkus</groupId><artifactId>quarkus-universe-bom</artifactId><version>${quarkus.version}</version><type>pom</type><scope>import</scope>'
codeSnip: "19 <maven.compiler.target>11</maven.compiler.target>\n20 <quarkus.version>1.10.5.Final</quarkus.version>\n21 <compiler-plugin.version>3.8.1</compiler-plugin.version>\n22 <maven.compiler.parameters>true</maven.compiler.parameters>\n23 </properties>\n24 \n25 <dependencyManagement>\n26 <dependencies>\n27 <dependency>\n28 <groupId>io.quarkus</groupId>\n29 <artifactId>quarkus-universe-bom</artifactId>\n30 <version>${quarkus.version}</version>\n31 <type>pom</type>\n32 <scope>import</scope>\n33 </dependency>\n34 </dependencies>\n35 </dependencyManagement>\n36 \n37 <dependencies>\n38 <dependency>\n39 <groupId>io.javaoperatorsdk</groupId>"
lineNumber: 28
variables:
data: dependency
innerText: "\n io.quarkus\n quarkus-universe-bom\n ${quarkus.version}\n pom\n import\n "
matchingXML: <groupId>io.quarkus</groupId><artifactId>quarkus-universe-bom</artifactId><version>${quarkus.version}</version><type>pom</type><scope>import</scope>
- uri: file:///examples/java/dummy/pom.xml
message: |-
POM XML dependencies - '<groupId>javax</groupId><artifactId>javaee-api</artifactId><!-- This leads to https://github.com/konveyor/analyzer-lsp/issues/390
Expand Down Expand Up @@ -1066,6 +1114,8 @@
message: ""
- uri: file:///examples/java-project/pom.xml
message: ""
- uri: file:///examples/java-project/quarkus-1-6-2-jar-exploded/META-INF/maven/io.javaoperatorsdk/quarkus/pom.xml
message: ""
- uri: file:///examples/java/dummy/pom.xml
message: ""
- uri: file:///examples/java/example/pom.xml
Expand Down Expand Up @@ -1163,6 +1213,12 @@
lineNumber: 191
variables:
matchingText: Apache
- uri: file:///examples/java-project/quarkus-1-6-2-jar-exploded/META-INF/MANIFEST.MF
message: ""
codeSnip: " 1 Manifest-Version: 1.0\n 2 Archiver-Version: Plexus Archiver\n 3 Created-By: Apache Maven 3.6.3\n 4 Built-By: runner\n 5 Build-Jdk: 11.0.9\n 6 \n"
lineNumber: 3
variables:
matchingText: Apache
- uri: file:///examples/java/beans.xml
message: ""
codeSnip: " 1 <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n 2 <!-- \n 3 * (C) Copyright IBM Corporation 2015.\n 4 *\n 5 * Licensed under the Apache License, Version 2.0 (the \"License\");\n 6 * you may not use this file except in compliance with the License.\n 7 * You may obtain a copy of the License at\n 8 *\n 9 * http://www.apache.org/licenses/LICENSE-2.0\n10 *\n11 * Unless required by applicable law or agreed to in writing, software\n12 * distributed under the License is distributed on an \"AS IS\" BASIS,\n13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n14 * See the License for the specific language governing permissions and\n15 * limitations under the License.\n16 -->"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
"sync"
"text/template"
Expand Down Expand Up @@ -247,7 +248,10 @@ func explode(ctx context.Context, log logr.Logger, archivePath, projectPath stri

if f.FileInfo().IsDir() {
// make sure execute bits are set so that fernflower can decompile
os.MkdirAll(filePath, f.Mode()|0111)
err := os.MkdirAll(filePath, f.Mode()|0111)
if err != nil {
log.V(5).Error(err, "failed to create directory when exploding the archive", "filePath", filePath)
}
continue
}

Expand Down Expand Up @@ -391,6 +395,22 @@ func explode(ctx context.Context, log logr.Logger, archivePath, projectPath stri
})
}
}
// any other files, move to java project as-is
default:
baseName := strings.ToValidUTF8(f.Name, "_")
re := regexp.MustCompile(`[^\w\-\.\\/]+`)
baseName = re.ReplaceAllString(baseName, "_")
destPath := filepath.Join(
projectPath, strings.Replace(filepath.Base(archivePath), ".", "-", -1)+"-exploded", baseName)
if err := os.MkdirAll(filepath.Dir(destPath), 0755); err != nil {
log.V(8).Error(err, "error creating directory for java file", "path", destPath)
continue
}
if err := moveFile(filePath, destPath); err != nil {
log.V(8).Error(err, "error moving decompiled file to project path",
"src", filePath, "dest", destPath)
continue
}
}
}

Expand Down Expand Up @@ -606,4 +626,4 @@ func toFilePathDependency(_ context.Context, filePath string) (javaArtifact, err
dep.Version = "0.0.0"
return dep, nil

}
}
Loading