-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
493 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
core/jarviz-core/src/main/java/org/kordamp/jarviz/core/JarFileAnalyzer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Copyright 2022-2023 The Jarviz authors. | ||
* | ||
* 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 | ||
* | ||
* https://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.kordamp.jarviz.core; | ||
|
||
import java.util.jar.JarFile; | ||
|
||
/** | ||
* @author Andres Almiray | ||
* @since 0.2.0 | ||
*/ | ||
public interface JarFileAnalyzer<R> extends JarAnalyzer<R> { | ||
void handle(JarFile jarFile); | ||
} |
28 changes: 28 additions & 0 deletions
28
core/jarviz-core/src/main/java/org/kordamp/jarviz/core/JarPathAnalyzer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Copyright 2022-2023 The Jarviz authors. | ||
* | ||
* 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 | ||
* | ||
* https://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.kordamp.jarviz.core; | ||
|
||
import java.nio.file.Path; | ||
|
||
/** | ||
* @author Andres Almiray | ||
* @since 0.2.0 | ||
*/ | ||
public interface JarPathAnalyzer<R> extends JarAnalyzer<R> { | ||
void handle(Path path); | ||
} |
100 changes: 100 additions & 0 deletions
100
...arviz-core/src/main/java/org/kordamp/jarviz/core/analyzers/ModuleNameJarPathAnalyzer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Copyright 2022-2023 The Jarviz authors. | ||
* | ||
* 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 | ||
* | ||
* https://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.kordamp.jarviz.core.analyzers; | ||
|
||
import org.kordamp.jarviz.core.JarPathAnalyzer; | ||
import org.kordamp.jarviz.core.model.ModuleName; | ||
|
||
import java.lang.module.FindException; | ||
import java.lang.module.InvalidModuleDescriptorException; | ||
import java.lang.module.ModuleDescriptor; | ||
import java.lang.module.ModuleFinder; | ||
import java.lang.module.ModuleReference; | ||
import java.nio.file.Path; | ||
import java.util.Optional; | ||
|
||
import static org.kordamp.jarviz.util.StringUtils.isBlank; | ||
import static org.kordamp.jarviz.util.StringUtils.isNotBlank; | ||
|
||
/** | ||
* @author Andres Almiray | ||
* @since 0.2.0 | ||
*/ | ||
public class ModuleNameJarPathAnalyzer implements JarPathAnalyzer<ModuleName> { | ||
private final String automaticModuleNameByManifest; | ||
private final String automaticModuleNameByFilename; | ||
private ModuleName moduleName; | ||
|
||
public ModuleNameJarPathAnalyzer(String automaticModuleNameByManifest, String automaticModuleNameByFilename) { | ||
this.automaticModuleNameByManifest = automaticModuleNameByManifest; | ||
this.automaticModuleNameByFilename = automaticModuleNameByFilename; | ||
} | ||
|
||
@Override | ||
public ModuleName getResult() { | ||
return moduleName; | ||
} | ||
|
||
@Override | ||
public void handle(Path path) { | ||
if (isNotBlank(automaticModuleNameByManifest)) { | ||
moduleName = ModuleName.fromAutomaticByManifest(automaticModuleNameByManifest, | ||
isAutomaticNameValid(automaticModuleNameByManifest).orElse(null)); | ||
} | ||
|
||
try { | ||
moduleName = ModuleFinder.of(path).findAll().stream() | ||
.map(ModuleReference::descriptor) | ||
.map(this::toModuleName) | ||
.findFirst() | ||
.get(); | ||
} catch (FindException fe) { | ||
// automatic by filename | ||
moduleName = ModuleName.fromAutomaticByFilename(automaticModuleNameByFilename, fe.getCause().getMessage()); | ||
} catch (InvalidModuleDescriptorException imde) { | ||
// explicit | ||
// TODO: read module name from [versioned] module-info.class | ||
moduleName = ModuleName.fromModuleDescriptor("", imde.getMessage()); | ||
} | ||
} | ||
|
||
private ModuleName toModuleName(ModuleDescriptor moduleDescriptor) { | ||
return ModuleName.fromModuleDescriptor(moduleDescriptor.name(), | ||
moduleDescriptor.isAutomatic() && isNotBlank(automaticModuleNameByManifest), | ||
moduleDescriptor.isAutomatic() && isBlank(automaticModuleNameByManifest) && isNotBlank(automaticModuleNameByFilename), | ||
isValid(moduleDescriptor.name()).orElse(null)); | ||
} | ||
|
||
private Optional<String> isAutomaticNameValid(String name) { | ||
try { | ||
ModuleDescriptor.newAutomaticModule(name); | ||
return Optional.empty(); | ||
} catch (IllegalArgumentException exception) { | ||
return Optional.of(exception.getMessage()); | ||
} | ||
} | ||
|
||
private Optional<String> isValid(String name) { | ||
try { | ||
ModuleDescriptor.newModule(name); | ||
return Optional.empty(); | ||
} catch (IllegalArgumentException exception) { | ||
return Optional.of(exception.getMessage()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
core/jarviz-core/src/main/java/org/kordamp/jarviz/core/model/ModuleName.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Copyright 2022-2023 The Jarviz authors. | ||
* | ||
* 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 | ||
* | ||
* https://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.kordamp.jarviz.core.model; | ||
|
||
/** | ||
* @author Andres Almiray | ||
* @since 0.2.0 | ||
*/ | ||
public class ModuleName { | ||
private final String moduleName; | ||
private final boolean automaticByManifest; | ||
private final boolean automaticByFilename; | ||
private final boolean valid; | ||
private final String reason; | ||
|
||
private ModuleName(String moduleName, boolean automaticByManifest, boolean automaticByFilename, String reason) { | ||
this.moduleName = moduleName; | ||
this.automaticByManifest = automaticByManifest; | ||
this.automaticByFilename = automaticByFilename; | ||
this.valid = null == reason; | ||
this.reason = reason; | ||
} | ||
|
||
public boolean isAutomatic() { | ||
return automaticByManifest || automaticByFilename; | ||
} | ||
|
||
public String getModuleName() { | ||
return moduleName; | ||
} | ||
|
||
public boolean isAutomaticByManifest() { | ||
return automaticByManifest; | ||
} | ||
|
||
public boolean isAutomaticByFilename() { | ||
return automaticByFilename; | ||
} | ||
|
||
public boolean isValid() { | ||
return valid; | ||
} | ||
|
||
public String getReason() { | ||
return reason; | ||
} | ||
|
||
public static ModuleName fromAutomaticByManifest(String moduleName, String reason) { | ||
return new ModuleName(moduleName, true, false, reason); | ||
} | ||
|
||
public static ModuleName fromAutomaticByFilename(String moduleName, String reason) { | ||
return new ModuleName(moduleName, false, true, reason); | ||
} | ||
|
||
public static ModuleName fromModuleDescriptor(String moduleName, String reason) { | ||
return fromModuleDescriptor(moduleName, false, false, reason); | ||
} | ||
|
||
public static ModuleName fromModuleDescriptor(String moduleName, boolean automaticByManifest, boolean automaticByFilename, String reason) { | ||
return new ModuleName(moduleName, automaticByManifest, automaticByFilename, reason); | ||
} | ||
} |
Oops, something went wrong.