AgentJarResolver.java 1.1 KB
/*
 * Decompiled with CFR 0_118.
 */
package com.adobe.cq.deserfw.impl.util;

import java.io.File;
import java.io.IOException;

public class AgentJarResolver {
    public static String getAgentPath(File agentFolder) throws IOException {
        if (agentFolder == null) {
            throw new IOException("agentFolder is null");
        }
        if (!agentFolder.isDirectory()) {
            throw new IOException("Agent folder not found:" + agentFolder.getAbsolutePath());
        }
        String[] files = agentFolder.list();
        String agent = null;
        for (String file : files) {
            if (!file.startsWith("notsoserial") || !file.endsWith(".jar") || file.contains("javadoc") || file.contains("sources")) continue;
            if (agent != null) {
                throw new IOException("Multiple agent files found in " + agentFolder.getAbsolutePath());
            }
            agent = file;
        }
        if (agent == null) {
            throw new IOException("No agent file found in " + agentFolder.getAbsolutePath());
        }
        return new File(agentFolder, agent).getAbsolutePath();
    }
}