streamlet-examples/JarInfo.java
author František Kučera <franta-hg@frantovo.cz>
Wed, 29 Jan 2020 18:05:13 +0100
branchv_0
changeset 72 f7b9db6fc32b
child 73 1a067a217454
permissions -rw-r--r--
streamlet examples: dirty implementation of Java helper classes + demo code


/**
 * Relational pipes
 * Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
import java.io.File;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.jar.JarFile;

public class JarInfo extends Streamlet {

	public static void main(String[] args) throws IOException {
		JarInfo s = new JarInfo();
		int status = s.run();
		System.exit(status);

		// TODO: return real values:
		JarFile jar = new JarFile(new File(args[0]));
		String mainClass = jar.getManifest() == null ? null : jar.getManifest().getMainAttributes().getValue("Main-Class");
		System.out.println("Name:       " + jar.getName());
		System.out.println("Comment:    " + jar.getComment());
		System.out.println("Entries:    " + jar.stream().count());
		System.out.println("Main class: " + mainClass);
	}

	protected List<Streamlet.AttributeMetadata> getOutputAttributesMetadata() {
		List<Streamlet.AttributeMetadata> result = new LinkedList<>();
		result.add(new Streamlet.AttributeMetadata("main_class", Streamlet.Type.STRING));
		return result;
	}

	protected List<Object> getOutputAttributes() {
		List<Object> result = new LinkedList<>();
		result.add("TODO: main class");
		return result;
	}
}