Skip to content

Commit

Permalink
Separate oshi-core and oshi-json projects (oshi#205)
Browse files Browse the repository at this point in the history
* Move oshi project into oshi-core directory

* Copy API interfaces to oshi-json directory

* Remove JSON from oshi-core

* Working oshi-json classes

* Set up multi-module pom.xml

* Using child property overrides to reduce file duplication

* Updated CHANGELOG
  • Loading branch information
dbwiddis authored Jun 24, 2016
1 parent 1e294da commit 6899008
Show file tree
Hide file tree
Showing 165 changed files with 3,660 additions and 612 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@
/.project
/.settings/
/.classpath
/oshi-*/target/
/oshi-*/bin/
/oshi-*/.project
/oshi-*/.settings/
/oshi-*/.classpath
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
3.0 (in progress)
================
* [#205](https://github.com/dblock/oshi/pull/190): Separated oshi-core and oshi-json modules - [@dbwiddis](https://github.com/dbwiddis).
* Your contribution here.

2.6.2 (6/21/2016)
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@
[![Eclipse Public License](http://img.shields.io/badge/license-Eclipse-blue.svg)](https://www.eclipse.org/legal/epl-v10.html)
[![Build Status](https://travis-ci.org/dblock/oshi.svg)](https://travis-ci.org/dblock/oshi)
[![Dependency Status](https://www.versioneye.com/user/projects/55fed58c601dd9001500005e/badge.svg?style=flat)](https://www.versioneye.com/user/projects/55fed58c601dd9001500005e)
[![Reference Status](https://www.versioneye.com/java/com.github.dblock:oshi-core/reference_badge.svg?style=flat-square)](https://www.versioneye.com/java/com.github.dblock:oshi-core/references)

OSHI is a free JNA-based (native) operating system and hardware information library for Java. It doesn't require any additional native DLLs and aims to provide a cross-platform implementation to retrieve system information, such as version, memory, CPU, disk, battery, displays, etc.
OSHI is a free JNA-based (native) operating system and hardware information library for Java. It doesn't require any additional native DLLs and aims to provide a cross-platform implementation to retrieve system information, such OS version, memory, CPU, disk, battery, displays, sensors, etc.

Essentials
----------
* [Find OSHI on Maven Central](http://search.maven.org/#search|ga|1|oshi-core)
* [Find OSHI on Maven Central](http://search.maven.org/#search|ga|1|oshi-)
* [Download OSHI 2.6.2](https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=com.github.dblock&a=oshi-core&v=2.6.2&e=jar) (Read [UPGRADING.md](UPGRADING.md) if upgrading from version 1.x.)
* [Download OSHI 3.0-SNAPSHOT](https://oss.sonatype.org/service/local/artifact/maven/redirect?r=snapshots&g=com.github.dblock&a=oshi-core&v=3.0-SNAPSHOT&e=jar)
* [Download oshi-core-3.0-SNAPSHOT](https://oss.sonatype.org/service/local/artifact/maven/redirect?r=snapshots&g=com.github.dblock&a=oshi-core&v=3.0-SNAPSHOT&e=jar)
* [Download oshi-json-3.0-SNAPSHOT](https://oss.sonatype.org/service/local/artifact/maven/redirect?r=snapshots&g=com.github.dblock&a=oshi-json&v=3.0-SNAPSHOT&e=jar)
* [View the API](http://dblock.github.io/oshi/apidocs/) - [View the FAQ](https://github.com/dblock/oshi/blob/master/FAQ.md) - [View the Site](http://dblock.github.io/oshi/)
* Dependencies:
* [Java Native Access (JNA)](https://github.com/java-native-access/jna)
* [Simple Logging Facade for Java (SLF4J)](http://www.slf4j.org/)
* [Java API for JSON Processing (javax.json)](https://jsonp.java.net/download.html)
* [Java API for JSON Processing (javax.json)](https://jsonp.java.net/download.html) (for oshi-json)
* Related projects:
* [oren](https://github.com/zcaudate/oren), a Clojure wrapper for OSHI
* [jHardware](https://github.com/profesorfalken/jHardware), a pure Java (no JNA) project providing similar information for Windows and Unix
Expand Down Expand Up @@ -47,7 +49,7 @@ Currently supported features

Output
-------------
OSHI provides output directly via java methods or in JSON format for each of its interfaces.
OSHI provides output directly via java methods or, for the `oshi-json` project, in JSON format for each of its interfaces.
By periodically polling dynamic information (e.g., every second), users can calculate and track changes.

The `main()` method of [SystemInfoTest](https://github.com/dblock/oshi/blob/master/src/test/java/oshi/SystemInfoTest.java) provides sample code demonstrating
Expand Down
28 changes: 28 additions & 0 deletions oshi-core/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.github.dblock</groupId>
<artifactId>oshi-parent</artifactId>
<version>3.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>oshi-core</artifactId>
<packaging>jar</packaging>
<name>oshi-core</name>
<properties>
<src.relative.loc>..</src.relative.loc>
</properties>
<dependencies>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna-platform</artifactId>
<version>4.2.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>[1.7,)</version>
</dependency>
</dependencies>
</project>
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,14 @@
*/
package oshi;

import javax.json.Json;
import javax.json.JsonBuilderFactory;
import javax.json.JsonObject;
import java.io.Serializable;

import com.sun.jna.Platform;

import oshi.hardware.HardwareAbstractionLayer;
import oshi.hardware.platform.linux.LinuxHardwareAbstractionLayer;
import oshi.hardware.platform.mac.MacHardwareAbstractionLayer;
import oshi.hardware.platform.windows.WindowsHardwareAbstractionLayer;
import oshi.json.NullAwareJsonObjectBuilder;
import oshi.json.OshiJsonObject;
import oshi.software.os.OperatingSystem;
import oshi.software.os.linux.LinuxOperatingSystem;
import oshi.software.os.mac.MacOperatingSystem;
Expand All @@ -43,13 +39,13 @@
*
* @author dblock[at]dblock[dot]org
*/
public class SystemInfo implements OshiJsonObject {
public class SystemInfo implements Serializable {

private static final long serialVersionUID = 1L;

private OperatingSystem _os = null;
private OperatingSystem os = null;

private HardwareAbstractionLayer _hardware = null;
private HardwareAbstractionLayer hardware = null;

private PlatformEnum currentPlatformEnum;

Expand All @@ -65,7 +61,12 @@ public class SystemInfo implements OshiJsonObject {
}
}

private JsonBuilderFactory jsonFactory = Json.createBuilderFactory(null);
/**
* @return Returns the currentPlatformEnum.
*/
public PlatformEnum getCurrentPlatformEnum() {
return currentPlatformEnum;
}

/**
* Creates a new instance of the appropriate platform-specific
Expand All @@ -74,23 +75,23 @@ public class SystemInfo implements OshiJsonObject {
* @return A new instance of {@link OperatingSystem}.
*/
public OperatingSystem getOperatingSystem() {
if (this._os == null) {
if (this.os == null) {
switch (this.currentPlatformEnum) {

case WINDOWS:
this._os = new WindowsOperatingSystem();
this.os = new WindowsOperatingSystem();
break;
case LINUX:
this._os = new LinuxOperatingSystem();
this.os = new LinuxOperatingSystem();
break;
case MACOSX:
this._os = new MacOperatingSystem();
this.os = new MacOperatingSystem();
break;
default:
throw new RuntimeException("Operating system not supported: " + Platform.getOSType());
}
}
return this._os;
return this.os;
}

/**
Expand All @@ -100,29 +101,22 @@ public OperatingSystem getOperatingSystem() {
* @return A new instance of {@link HardwareAbstractionLayer}.
*/
public HardwareAbstractionLayer getHardware() {
if (this._hardware == null) {
if (this.hardware == null) {
switch (this.currentPlatformEnum) {

case WINDOWS:
this._hardware = new WindowsHardwareAbstractionLayer();
this.hardware = new WindowsHardwareAbstractionLayer();
break;
case LINUX:
this._hardware = new LinuxHardwareAbstractionLayer();
this.hardware = new LinuxHardwareAbstractionLayer();
break;
case MACOSX:
this._hardware = new MacHardwareAbstractionLayer();
this.hardware = new MacHardwareAbstractionLayer();
break;
default:
throw new RuntimeException("Operating system not supported: " + Platform.getOSType());
}
}
return this._hardware;
}

@Override
public JsonObject toJSON() {
return NullAwareJsonObjectBuilder.wrap(jsonFactory.createObjectBuilder())
.add("platform", this.currentPlatformEnum.toString())
.add("operatingSystem", getOperatingSystem().toJSON()).add("hardware", getHardware().toJSON()).build();
return this.hardware;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
*/
package oshi.hardware;

import oshi.json.OshiJsonObject;
import java.io.Serializable;

import oshi.software.os.OSProcess;

/**
Expand All @@ -28,7 +29,7 @@
*
* @author dblock[at]dblock[dot]org
*/
public interface CentralProcessor extends OshiJsonObject {
public interface CentralProcessor extends Serializable {
/**
* Processor vendor.
*
Expand Down Expand Up @@ -106,37 +107,37 @@ public interface CentralProcessor extends OshiJsonObject {
void setCpu64(boolean cpu64);

/**
* @return the _stepping
* @return the stepping
*/
String getStepping();

/**
* @param _stepping
* the _stepping to set
* @param stepping
* the stepping to set
*/
void setStepping(String _stepping);
void setStepping(String stepping);

/**
* @return the _model
* @return the model
*/
String getModel();

/**
* @param _model
* the _model to set
* @param model
* the model to set
*/
void setModel(String _model);
void setModel(String model);

/**
* @return the _family
* @return the family
*/
String getFamily();

/**
* @param _family
* the _family to set
* @param family
* the family to set
*/
void setFamily(String _family);
void setFamily(String family);

/**
* Returns the "recent cpu usage" for the whole system by counting ticks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
*/
package oshi.hardware;

import oshi.json.OshiJsonObject;
import java.io.Serializable;

/**
* Disks refers to hard drives installed in the machine.
*
* @author enrico[dot]bianchi[at]gmail[dot]com
*/
public interface Disks extends OshiJsonObject {
public interface Disks extends Serializable {

/**
* Get hard drives on this machine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
*/
package oshi.hardware;

import oshi.json.OshiJsonObject;
import java.io.Serializable;

/**
* Display refers to the information regarding a video source and monitor
* identified by the EDID standard.
*
* @author widdis[at]gmail[dot]com
*/
public interface Display extends OshiJsonObject {
public interface Display extends Serializable {
/**
* The EDID byte array.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package oshi.hardware;

import oshi.json.OshiJsonObject;
import java.io.Serializable;

/**
* Memory refers to the state information of a computing system, as it is kept
Expand All @@ -30,7 +30,7 @@
*
* @author dblock[at]dblock[dot]org
*/
public interface GlobalMemory extends OshiJsonObject {
public interface GlobalMemory extends Serializable {
/**
* The amount of actual physical memory, in bytes.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,22 @@
*/
package oshi.hardware;

import javax.json.Json;
import javax.json.JsonBuilderFactory;
import javax.json.JsonObject;

import oshi.json.NullAwareJsonObjectBuilder;
import oshi.json.OshiJsonObject;
import java.io.Serializable;

/**
* Store object of disk attributes.
* A storage mechanism where data are recorded by various electronic, magnetic,
* optical, or mechanical changes to a surface layer of one or more rotating
* disks or or flash storage such as a removable or solid state drive. In
* constrast to a File System, defining the way an Operating system uses the
* storage, the Disk Store represents the hardware which a FileSystem uses for
* its File Stores.
*
* @author enrico[dot]bianchi[at]gmail[dot]com
*/
public class HWDiskStore implements OshiJsonObject {
public class HWDiskStore implements Serializable {

private static final long serialVersionUID = 1L;

private JsonBuilderFactory jsonFactory = Json.createBuilderFactory(null);

private String name;
private String model;
private String serial;
Expand Down Expand Up @@ -180,14 +178,4 @@ public long getWrites() {
public void setWrites(long writes) {
this.writes = writes;
}

/**
* {@inheritDoc}
*/
@Override
public JsonObject toJSON() {
return NullAwareJsonObjectBuilder.wrap(jsonFactory.createObjectBuilder()).add("name", getName())
.add("model", getModel()).add("serial", getSerial()).add("size", getSize()).add("reads", getReads())
.add("writes", getWrites()).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
*/
package oshi.hardware;

import oshi.json.OshiJsonObject;
import java.io.Serializable;

import oshi.software.os.FileSystem;
import oshi.software.os.OSFileStore;

Expand All @@ -28,7 +29,7 @@
*
* @author dblock[at]dblock[dot]org
*/
public interface HardwareAbstractionLayer extends OshiJsonObject {
public interface HardwareAbstractionLayer extends Serializable {

/**
* Instantiates a {@link CentralProcessor} object. This represents one or
Expand Down
Loading

0 comments on commit 6899008

Please sign in to comment.