Skip to content

Commit

Permalink
Merge pull request #56 from IBM/issue-55-establish-versioning
Browse files Browse the repository at this point in the history
Issue 55 establish versioning
  • Loading branch information
rahlk authored Oct 17, 2024
2 parents c9b1400 + 76577bd commit d10d427
Show file tree
Hide file tree
Showing 23 changed files with 110 additions and 62 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ jobs:

- name: Determine new tag
id: newtag
run: echo "::set-output name=tag::$(date +'%Y%m%dT%H%M%S')"
run: |
VERSION=$(java -jar build/libs/codeanalyzer.jar --version | awk '{print $2}')
TAG="v$VERSION"
echo "tag=$TAG" >> $GITHUB_OUTPUT
- name: Create Git Tag
run: |
Expand Down
60 changes: 54 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ plugins {
id 'org.graalvm.buildtools.native' version '0.9.28'
}

version = 'latest'
// Get the version from the property file first
version = new Properties().with {property ->
file("gradle.properties").withInputStream {property.load(it)}
property.getProperty("version")
}

repositories {
mavenCentral()
Expand All @@ -30,7 +34,7 @@ if (project.hasProperty('mainClass')) {
mainClassName = project.getProperty('mainClass')
} else {
// use a default
mainClassName =("com.ibm.northstar.CodeAnalyzer")
mainClassName =("com.ibm.cldk.CodeAnalyzer")
}

sourceSets {
Expand Down Expand Up @@ -124,9 +128,9 @@ task fatJar(type: Jar) {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
manifest {
attributes(
'Implementation-Title': 'Northstar Codeanalyzer',
'Implementation-Title': 'codeanalyzer',
'Implementation-Version': project.version,
'Main-Class': 'com.ibm.northstar.CodeAnalyzer'
'Main-Class': 'com.ibm.cldk.CodeAnalyzer'
)
}

Expand All @@ -148,7 +152,7 @@ graalvmNative {
binaries {
main {
imageName = "codeanalyzer"
mainClass = "com.ibm.northstar.CodeAnalyzer"
mainClass = "com.ibm.cldk.CodeAnalyzer"
buildArgs.add("-Ob")
buildArgs.add("-march=compatibility")
buildArgs.add("--no-fallback")
Expand Down Expand Up @@ -185,7 +189,7 @@ task createRelease {
doLast {
def releaseTitle = 'latest'
def hostName = '[email protected]'
def repo = 'northstar/codeanalyzer'
def repo = 'cldk/codeanalyzer'

// Command to create release
def delete = "gh release delete latest --cleanup-tag --yes -R ${hostName}:${repo}"//
Expand All @@ -207,4 +211,48 @@ task createRelease {

}

tasks.register('bumpVersion') {
description = 'Bumps the version number (patch, minor, or major)'
group = 'Versioning'

doLast {
def versionFile = file('gradle.properties')
def versionFileText = versionFile.text
def versionPattern = /version\s*=\s*(\d+)\.(\d+)\.(\d+)/
def matcher = (versionFileText =~ versionPattern)

if (matcher.find()) {
def major = matcher.group(1) as int
def minor = matcher.group(2) as int
def patch = matcher.group(3) as int

def bumpType = project.hasProperty('bumpType') ? project.bumpType : 'patch'

switch (bumpType) {
case 'major':
major++
minor = 0
patch = 0
break
case 'minor':
minor++
patch = 0
break
case 'patch':
default:
patch++
break
}

def newVersion = "${major}.${minor}.${patch}"
def updatedContent = versionFileText.replaceFirst(versionPattern, "version=$newVersion")
versionFile.text = updatedContent

println "Version bumped to $newVersion"
} else {
throw new GradleException("Version not found in gradle.properties")
}
}
}

nativeCompile.finalizedBy copyNativeExecutable
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version=1.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
limitations under the License.
*/

package com.ibm.northstar;
package com.ibm.cldk;

import com.github.javaparser.Problem;
import com.google.common.reflect.TypeToken;
import com.google.gson.*;
import com.ibm.northstar.entities.JavaCompilationUnit;
import com.ibm.northstar.utils.BuildProject;
import com.ibm.northstar.utils.Log;
import com.ibm.cldk.entities.JavaCompilationUnit;
import com.ibm.cldk.utils.BuildProject;
import com.ibm.cldk.utils.Log;
import com.ibm.wala.ipa.callgraph.CallGraphBuilderCancelException;
import com.ibm.wala.ipa.cha.ClassHierarchyException;
import org.apache.commons.lang3.tuple.Pair;
Expand All @@ -38,10 +38,17 @@
import java.util.Map;
import java.util.stream.Collectors;


class VersionProvider implements CommandLine.IVersionProvider {
public String[] getVersion() throws Exception {
String version = getClass().getPackage().getImplementationVersion();
return new String[]{ "codeanalyzer " + (version != null ? version : "unknown") };
}
}
/**
* The type Code analyzer.
*/
@Command(name = "codeanalyzer", mixinStandardHelpOptions = true, sortOptions = false, version = "codeanalyzer v1.1", description = "Convert java binary into a comprehensive system dependency graph.")
@Command(name = "codeanalyzer", mixinStandardHelpOptions = true, sortOptions = false, versionProvider = VersionProvider.class, description = "Analyze java application.")
public class CodeAnalyzer implements Runnable {

@Option(names = {"-i", "--input"}, description = "Path to the project root directory.")
Expand All @@ -62,6 +69,7 @@ public class CodeAnalyzer implements Runnable {
@Option(names = {"--no-build"}, description = "Do not build your application. Use this option if you have already built your application.")
private static boolean noBuild = false;


@Option(names = {"-a", "--analysis-level"}, description = "Level of analysis to perform. Options: 1 (for just symbol table) or 2 (for call graph). Default: 1")
private static int analysisLevel = 1;

Expand All @@ -70,7 +78,6 @@ public class CodeAnalyzer implements Runnable {

private static final String outputFileName = "analysis.json";


public static Gson gson = new GsonBuilder()
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.setPrettyPrinting()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ibm.northstar;
package com.ibm.cldk;

import com.github.javaparser.JavaParser;
import com.github.javaparser.ParseResult;
Expand All @@ -23,8 +23,8 @@
import com.github.javaparser.utils.SourceRoot;
import com.google.common.collect.Table;
import com.google.common.collect.Tables;
import com.ibm.northstar.entities.*;
import com.ibm.northstar.utils.Log;
import com.ibm.cldk.entities.*;
import com.ibm.cldk.utils.Log;
import org.apache.commons.lang3.tuple.Pair;

import java.io.IOException;
Expand Down Expand Up @@ -106,7 +106,7 @@ private static JavaCompilationUnit processCompilationUnit(CompilationUnit parseR
.map(typeDecl -> {
// get type name and initialize the type object
String typeName = typeDecl.getFullyQualifiedName().get().toString();
com.ibm.northstar.entities.Type typeNode = new com.ibm.northstar.entities.Type();
com.ibm.cldk.entities.Type typeNode = new com.ibm.cldk.entities.Type();

if (typeDecl instanceof ClassOrInterfaceDeclaration) {
ClassOrInterfaceDeclaration classDecl = (ClassOrInterfaceDeclaration)typeDecl;
Expand Down Expand Up @@ -156,7 +156,7 @@ private static JavaCompilationUnit processCompilationUnit(CompilationUnit parseR
// TODO: handle AnnotationDeclaration, RecordDeclaration
// set the common type attributes only
Log.warn("Found unsupported type declaration: "+typeDecl.toString());
typeNode = new com.ibm.northstar.entities.Type();
typeNode = new com.ibm.cldk.entities.Type();
}

/* set common attributes of types that available in type declarations:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
limitations under the License.
*/

package com.ibm.northstar;

import com.ibm.northstar.entities.AbstractGraphEdge;
import com.ibm.northstar.entities.CallEdge;
import com.ibm.northstar.entities.Callable;
import com.ibm.northstar.entities.SystemDepEdge;
import com.ibm.northstar.utils.AnalysisUtils;
import com.ibm.northstar.utils.Log;
import com.ibm.northstar.utils.ScopeUtils;
package com.ibm.cldk;

import com.ibm.cldk.entities.AbstractGraphEdge;
import com.ibm.cldk.entities.CallEdge;
import com.ibm.cldk.entities.Callable;
import com.ibm.cldk.entities.SystemDepEdge;
import com.ibm.cldk.utils.AnalysisUtils;
import com.ibm.cldk.utils.Log;
import com.ibm.cldk.utils.ScopeUtils;
import com.ibm.wala.cast.ir.ssa.AstIRFactory;
import com.ibm.wala.cast.java.translator.jdt.ecj.ECJClassLoaderFactory;
import com.ibm.wala.classLoader.CallSiteReference;
Expand Down Expand Up @@ -52,8 +52,8 @@
import java.util.function.BiFunction;
import java.util.function.Supplier;

import static com.ibm.northstar.CodeAnalyzer.gson;
import static com.ibm.northstar.utils.AnalysisUtils.*;
import static com.ibm.cldk.CodeAnalyzer.gson;
import static com.ibm.cldk.utils.AnalysisUtils.*;

/**
* The type Sdg 2 json.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
limitations under the License.
*/

package com.ibm.northstar.entities;
package com.ibm.cldk.entities;

import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.slicer.Statement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
limitations under the License.
*/

package com.ibm.northstar.entities;
package com.ibm.cldk.entities;

import org.jgrapht.nio.Attribute;
import org.jgrapht.nio.DefaultAttribute;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ibm.northstar.entities;
package com.ibm.cldk.entities;

import lombok.Data;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ibm.northstar.entities;
package com.ibm.cldk.entities;

import lombok.Data;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ibm.northstar.entities;
package com.ibm.cldk.entities;

import lombok.Data;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ibm.northstar.entities;
package com.ibm.cldk.entities;

import lombok.Data;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ibm.northstar.entities;
package com.ibm.cldk.entities;

import lombok.Data;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package com.ibm.northstar.entities;
package com.ibm.cldk.entities;

import lombok.Data;
import org.jgrapht.nio.Attribute;
import org.jgrapht.nio.DefaultAttribute;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
public class ParameterInCallable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
limitations under the License.
*/

package com.ibm.northstar.entities;
package com.ibm.cldk.entities;

import com.ibm.wala.ipa.slicer.Statement;
import org.apache.commons.lang3.builder.HashCodeBuilder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ibm.northstar.entities;
package com.ibm.cldk.entities;

import lombok.Data;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.ibm.northstar.entities;
package com.ibm.cldk.entities;

import lombok.Data;

import java.util.List;

@Data
public class VariableDeclaration {
private String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
limitations under the License.
*/

package com.ibm.northstar.utils;
package com.ibm.cldk.utils;

import static com.ibm.northstar.SymbolTable.declaredMethodsAndConstructors;
import static com.ibm.cldk.SymbolTable.declaredMethodsAndConstructors;

import com.ibm.northstar.entities.Callable;
import com.ibm.northstar.entities.ParameterInCallable;
import com.ibm.cldk.entities.Callable;
import com.ibm.cldk.entities.ParameterInCallable;
import com.ibm.wala.classLoader.IClass;
import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.ipa.callgraph.Entrypoint;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ibm.northstar.utils;
package com.ibm.cldk.utils;

import java.io.BufferedReader;
import java.io.File;
Expand All @@ -10,7 +10,7 @@
import java.util.Arrays;
import java.util.List;

import static com.ibm.northstar.utils.ProjectDirectoryScanner.classFilesStream;
import static com.ibm.cldk.utils.ProjectDirectoryScanner.classFilesStream;

public class BuildProject {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
limitations under the License.
*/

package com.ibm.northstar.utils;
package com.ibm.cldk.utils;

import java.time.LocalDateTime;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ibm.northstar.utils;
package com.ibm.cldk.utils;

import java.io.IOException;
import java.nio.file.Files;
Expand Down
Loading

0 comments on commit d10d427

Please sign in to comment.