Skip to content

Commit

Permalink
MID-8842 copied ninja code to support-4.4 (e6cb5f7) compilations issues
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Jun 20, 2023
1 parent 8d19a54 commit e48089f
Show file tree
Hide file tree
Showing 144 changed files with 8,874 additions and 1,274 deletions.
131 changes: 87 additions & 44 deletions tools/ninja/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<!--
~ Copyright (C) 2010-2021 Evolveum and contributors
~ Copyright (C) 2010-2022 Evolveum and contributors
~
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
Expand Down Expand Up @@ -30,18 +30,38 @@
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</dependency>

<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
</dependency>

<dependency>
<groupId>com.evolveum.commons</groupId>
<artifactId>util</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.evolveum.prism</groupId>
<artifactId>prism-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.evolveum.prism</groupId>
<artifactId>prism-impl</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.evolveum.midpoint.repo</groupId>
<artifactId>repo-api</artifactId>
Expand All @@ -57,44 +77,12 @@
<artifactId>schema</artifactId>
<version>${midpoint.version}</version>
</dependency>
<dependency>
<groupId>com.evolveum.commons</groupId>
<artifactId>util</artifactId>
<version>${midpoint.version}</version>
<exclusions>
<exclusion>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>com.evolveum.midpoint.infra</groupId>
<artifactId>common</artifactId>
<version>${midpoint.version}</version>
</dependency>
<dependency>
<groupId>com.evolveum.prism</groupId>
<artifactId>prism-api</artifactId>
<version>${midpoint.version}</version>
<exclusions>
<exclusion>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.evolveum.prism</groupId>
<artifactId>prism-impl</artifactId>
<version>${midpoint.version}</version>
<exclusions>
<exclusion>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.evolveum.midpoint.repo</groupId>
<artifactId>repo-sqlbase</artifactId>
Expand All @@ -110,7 +98,6 @@
<groupId>com.evolveum.midpoint.repo</groupId>
<artifactId>repo-sqale</artifactId>
<version>${midpoint.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.evolveum.midpoint</groupId>
Expand All @@ -130,11 +117,15 @@
<version>${midpoint.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.evolveum.midpoint.repo</groupId>
<artifactId>system-init</artifactId>
<version>${midpoint.version}</version>
<scope>runtime</scope>
<exclusions>
<exclusion>
<groupId>org.opensaml</groupId>
Expand All @@ -147,12 +138,36 @@
</exclusions>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-configuration2</artifactId>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>
<dependency>
<groupId>com.squareup.okio</groupId>
<artifactId>okio-jvm</artifactId>
<version>3.0.0</version>
</dependency>

<dependency>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId>
<version>2.4.0</version>
</dependency>

<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
Expand All @@ -169,10 +184,6 @@
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
Expand All @@ -185,7 +196,6 @@
<dependency>
<groupId>jakarta.xml.ws</groupId>
<artifactId>jakarta.xml.ws-api</artifactId>
<scope>runtime</scope>
</dependency>

<!-- LOGGING -->
Expand All @@ -204,7 +214,11 @@
</dependency>

<!-- TEST DEPENDENCIES -->

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<!-- Required for surefire plugin not to complain -->
<groupId>org.testng</groupId>
Expand All @@ -222,6 +236,35 @@
<artifactId>test-ng</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.evolveum.midpoint.repo</groupId>
<artifactId>task-quartz-impl</artifactId>
<version>${midpoint.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.evolveum.midpoint.repo</groupId>
<artifactId>repo-test-util</artifactId>
<version>${midpoint.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.evolveum.midpoint.repo</groupId>
<artifactId>security-impl</artifactId>
<version>${midpoint.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc11</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
53 changes: 17 additions & 36 deletions tools/ninja/src/main/java/com/evolveum/midpoint/ninja/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import com.beust.jcommander.JCommander;
import com.beust.jcommander.ParameterException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.fusesource.jansi.AnsiConsole;

import com.evolveum.midpoint.ninja.action.Action;
import com.evolveum.midpoint.ninja.action.BaseOptions;
import com.evolveum.midpoint.ninja.impl.Command;
import com.evolveum.midpoint.ninja.impl.NinjaContext;
import com.evolveum.midpoint.ninja.opts.BaseOptions;
import com.evolveum.midpoint.ninja.opts.ConnectionOptions;
import com.evolveum.midpoint.ninja.util.NinjaUtils;

public class Main {
Expand All @@ -30,6 +33,8 @@ public static void main(String[] args) {
}

protected <T> void run(String[] args) {
AnsiConsole.systemInstall();

JCommander jc = NinjaUtils.setupCommandLineParser();

try {
Expand All @@ -41,10 +46,9 @@ protected <T> void run(String[] args) {

String parsedCommand = jc.getParsedCommand();

BaseOptions base = Objects.requireNonNull(
NinjaUtils.getOptions(jc, BaseOptions.class));
BaseOptions base = Objects.requireNonNull(NinjaUtils.getOptions(jc.getObjects(), BaseOptions.class));

if (base.isVersion()) {
if (BooleanUtils.isTrue(base.isVersion())) {
try {
URL versionResource = Objects.requireNonNull(
Main.class.getResource("/version"));
Expand All @@ -71,59 +75,36 @@ protected <T> void run(String[] args) {

NinjaContext context = null;
try {
ConnectionOptions connection = Objects.requireNonNull(
NinjaUtils.getOptions(jc, ConnectionOptions.class));
Action<T> action;
if (connection.isUseWebservice()) {
action = Command.createRestAction(parsedCommand);
} else {
action = Command.createRepositoryAction(parsedCommand);
}
Action<T, ?> action = Command.createAction(parsedCommand);

if (action == null) {
String strConnection = connection.isUseWebservice() ? "webservice" : "repository";
System.err.println("Action for command '" + parsedCommand + "' not found (connection: '"
+ strConnection + "')");
System.err.println("Action for command '" + parsedCommand + "' not found");
return;
}

//noinspection unchecked
T options = (T) jc.getCommands().get(parsedCommand).getObjects().get(0);
List<Object> allOptions = new ArrayList<>(jc.getObjects());
allOptions.add(options);

context = new NinjaContext(jc);

preInit(context);
context = new NinjaContext(allOptions, action.getApplicationContextLevel(allOptions));

action.init(context, options);

preExecute(context);

action.execute();

postExecute(context);
} catch (Exception ex) {
handleException(base, ex);
} finally {
cleanupResources(base, context);
}
}

protected void preInit(NinjaContext context) {
// intentionally left out empty
}

protected void preExecute(NinjaContext context) {
// intentionally left out empty
}

protected void postExecute(NinjaContext context) {
// intentionally left out empty
AnsiConsole.systemUninstall();
}
}

private void cleanupResources(BaseOptions opts, NinjaContext context) {
try {
if (context != null) {
context.destroy();
context.close();
}
} catch (Exception ex) {
if (opts.isVerbose()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2021 Evolveum and contributors
* Copyright (C) 2010-2022 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
Expand All @@ -17,7 +17,6 @@
import com.evolveum.midpoint.ninja.action.worker.SearchProducerWorker;
import com.evolveum.midpoint.ninja.impl.LogTarget;
import com.evolveum.midpoint.ninja.impl.NinjaContext;
import com.evolveum.midpoint.ninja.opts.ExportOptions;
import com.evolveum.midpoint.ninja.util.NinjaUtils;
import com.evolveum.midpoint.ninja.util.OperationStatus;
import com.evolveum.midpoint.prism.PrismContext;
Expand All @@ -42,7 +41,7 @@
*
* @param <O> options class
*/
public abstract class AbstractRepositorySearchAction<O extends ExportOptions> extends RepositoryAction<O> {
public abstract class AbstractRepositorySearchAction<O extends ExportOptions> extends RepositoryAction<O, Void> {

private static final String DOT_CLASS = AbstractRepositorySearchAction.class.getName() + ".";

Expand All @@ -56,11 +55,11 @@ public abstract class AbstractRepositorySearchAction<O extends ExportOptions> ex
protected abstract Runnable createConsumer(BlockingQueue<ObjectType> queue, OperationStatus operation);

protected String getOperationName() {
return this.getClass().getName() + "." + getOperationShortName();
return getClass().getName() + "." + getOperationShortName();
}

@Override
public void execute() throws Exception {
public Void execute() throws Exception {
OperationResult result = new OperationResult(getOperationName());
OperationStatus operation = new OperationStatus(context, result);

Expand Down Expand Up @@ -98,6 +97,8 @@ public void execute() throws Exception {
}

handleResultOnFinish(operation, "Finished " + getOperationShortName());

return null;
}

@Override
Expand Down Expand Up @@ -157,7 +158,7 @@ private List<SearchProducerWorker> createProducersForShadows(
List<SearchProducerWorker> shadowProducers = new ArrayList<>();

try {
RepositoryService repository = this.context.getRepository();
RepositoryService repository = context.getRepository();

Collection<SelectorOptions<GetOperationOptions>> opts =
SelectorOptions.createCollection(GetOperationOptions.createRaw());
Expand Down

0 comments on commit e48089f

Please sign in to comment.