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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
72
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
/**
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
 * Relational pipes
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 * Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info)
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
 *
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
 * This program is free software: you can redistribute it and/or modify
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
 * it under the terms of the GNU General Public License as published by
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 * the Free Software Foundation, version 3 of the License.
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 *
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 * GNU General Public License for more details.
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 *
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
 */
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
import java.io.File;
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
import java.io.IOException;
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
import java.util.LinkedList;
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
import java.util.List;
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
import java.util.jar.JarFile;
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
public class JarInfo extends Streamlet {
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
	public static void main(String[] args) throws IOException {
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
		JarInfo s = new JarInfo();
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
		int status = s.run();
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
		System.exit(status);
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
		// TODO: return real values:
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
		JarFile jar = new JarFile(new File(args[0]));
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
		String mainClass = jar.getManifest() == null ? null : jar.getManifest().getMainAttributes().getValue("Main-Class");
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
		System.out.println("Name:       " + jar.getName());
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
		System.out.println("Comment:    " + jar.getComment());
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
		System.out.println("Entries:    " + jar.stream().count());
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
		System.out.println("Main class: " + mainClass);
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
	}
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
	protected List<Streamlet.AttributeMetadata> getOutputAttributesMetadata() {
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
		List<Streamlet.AttributeMetadata> result = new LinkedList<>();
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
		result.add(new Streamlet.AttributeMetadata("main_class", Streamlet.Type.STRING));
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
		return result;
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
	}
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
	protected List<Object> getOutputAttributes() {
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
		List<Object> result = new LinkedList<>();
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
		result.add("TODO: main class");
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
		return result;
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
	}
f7b9db6fc32b streamlet examples: dirty implementation of Java helper classes + demo code
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
}